Q:

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

belongs to collection: Java String Programs

0

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.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to trim a given string using String.trim() met... >>
<< How to convert a character array to string in Java...