String length() in java

length():Returns the length of this string.

Syntax:

public int length()

Example:

StringLengthExample.java

/**
 * This program is used to show the use of length() method.
 * @author w3spoint
 */
class TestString{
	String str = "www.w3spoint.com";
 
	/**
	 * This method is used to show the use of length() method.
	 * @author w3spoint
	 */
	public void stringLengthTest(){
		System.out.println(str.length());
	}
}
 
public class StringLengthExample {
	public static void main(String args[]){
		//creating TestString object
		TestString obj = new TestString();
 
		//method call
		obj.stringLengthTest();
	}
}

Output:

16

Download this example.
 
Next Topic: trim() String functions in java with example.
Previous Topic: intern() String functions in java with example.

 

Content Protection by DMCA.com
Please Share