-
str.toCharArray().length
should work. -
Or how about:
str.lastIndexOf("")
Probably even runs in constant time 🙂
-
Another one
Matcher m = Pattern.compile("$").matcher(str); m.find(); int length = m.end();
-
One of the dumbest solutions:
str.split("").length - 1
-
Is this cheating:
new StringBuilder(str).length()
? 🙂