Walk over how to get the length of a given String object.
Source Code
package com.beginner.examples;
public class StringLength {
public static void main(String[] args) {
//Create String.
String string = "Hello World";
/*
* To get the length of given String use the method length() of Java String.
*/
int result = string.length();
System.out.println("The length of String is : " + result);
}
}
Output:
The length of String is : 11