How can I find the length of a String without using the length()
method of String class?
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()
? :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With