CodesJava

Easy learning with example program codes

length() String functions 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 codesjava
 */
class TestString{
	String str = "www.codesjava.com";
 
	/**
	 * This method is used to show the use of length() method.
	 * @author codesjava
	 */
	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:

17

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

 

Please follow and like us:
error
Posted in Java   








Copyright © 2019 CodesJava DMCA.com Protection Status