• August 28, 2014
  • Core Java
  • Comments Off on length() String functions in java

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

20

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

Related Topics:

String handling in java with example.
String Comparison in java with example.
String concatenation in java with example.
Substring in java with example.
How to write Immutable class in java with example.
toString() method in java with example.
Commonly used methods of String Class with example.
charAt(int index) String function in java with example.
startsWith(String prefix) and endsWith(String suffix) String functions in java.
indexOf(String str) and lastIndexOf(String str) String functions in java.
toLowerCase() and toUpperCase() String functions in java.
intern() String functions in java with example.
length() String functions in java with example.
trim() String functions in java with example.

 


Comments are closed.