How to Get Length of String in Java


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
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments