Length
The number of char
s 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"
);
1
This is different from the number of unicode codepoints.