Java String Length Example
- /*
- Java String Length Example
- This example shows how to get a length of a given String object.
- */
- public class StringLengthExample {
- public static void main(String[] args) {
- //declare the String object
- String str = "Hello World";
- //length() method of String returns the length of a String.
- int length = str.length();
- System.out.println("Length of a String is : " + length);
- }
- }
- /*
- Output of a program would be:
- Length of a String is : 11
- */



