How to correctly compute the length of a String in Java?

Viewed 47088

I know there is String#length and the various methods in Character which more or less work on code units/code points.

What is the suggested way in Java to actually return the result as specified by Unicode standards (UAX#29), taking things like language/locale, normalization and grapheme clusters into account?

5 Answers

.indexOf() method gives a hint:

int length = (yourString + "whatever").indexOf("whatever");
Related