Java String length() Method Example

The length of a string is the number of characters that it contains. To obtain this value, call the length() method, shown here:
int length()

Java String length() Method Example

Example to print the length of string "Java Guides".
public class LengthExample {
    public static void main(String[] args) {
        String str = new String("Java Guides");
        int length = str.length();
        System.out.println(" length of the string '" + str + "' is :: " + length);
    }
}

Output:
 length of the string 'Java Guides' is:: 11 

Reference


Comments