Latest web development tutorials

Java length () method

Java String class Java String class


length () method returns the length of the string.

The length of the string is equal to the number of 16-bit Unicode code units.

grammar

public int length()

parameter

  • no

return value

Returns the string length.

Examples

public class Test {
	public static void main(String args[]) {
		String Str1 = new String("www.w3big.com");
		String Str2 = new String("w3big" );

		System.out.print("字符串 Str1 长度 :");
		System.out.println(Str1.length());
		System.out.print("字符串 Str2 长度 :");
		System.out.println(Str2.length());
	}
}

The above program execution results:

字符串 Str1 长度 :14
字符串 Str2 长度 :6

Java String class Java String class