Here's another way:
int length = 0;
while (!str.equals("")) {
str = str.substring(1);
++length;
}
In the same spirit (although much less efficient):
String regex = "(?s)";
int length = 0;
while (!str.matches(regex)) {
regex += ".";
++length;
}
Or even:
int length = 0;
while (!str.matches("(?s).{" + length + "}")) {
++length;
}