Length of the String without using length() method

java, string

Solution

`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()`? :-)

Problem

How can I find the length of a String without using the `length()` method of String class?

Original source