How to calculate length of the string using String.length() method in Java?

String.length() method in Java: Here, we will learn how to calculate/get the length of the string using String.length() in Java?

Given a string and we have to get the length of the string using String.length() method in Java?

String.length()

It is a predefined (built-in) method of String class in Java; it returns length of the string.

Consider the program:

import java.lang.*;

public class JavaStringLengthPrg
{
	public static void main(String []args)
	{
		int len=0;

		/*create string object*/
		String str="includehelp.com";
		
		//getting length of the string
		len = str.length();
		
		//printing length
		System.out.println("String Length is = "+ len);
	}
}

Output

String Length is = 15

Java String Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.