Return the number of characters in a string:
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";System.out.println(txt.length());
txt
out
The length() method retrieves the length of a given string.
length()
Note: An empty string has a length of 0.
public int length()
None.
Returns:
An integer value representing the length of the string.