The number of chars which comprise a String can be accessed by using .length().1
String fruit = "strawberry";
int numberOfChars = fruit.length();
// strawberry is 10 characters long
System.out.println(
fruit + " is " numberOfChars + " characters long"
);Footnotes
-
This is different from the number of unicode codepoints. ↩