int length()

Java String类Java String类

length() 方法用于返回字符串的长度。

长度等于字符串中 16 位 Unicode 代码单元的数量。

语法

public int length()
w)/3)/x)/u)/e.com提供本手册内容,请勿盗用!

参数

返回值

返回字符串长度。

实例

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

		System.out.print("字符串 Str1 长度 :");
		System.out.println(Str1.length());
		System.out.print("字符串 Str2 长度 :");
		System.out.println(Str2.length());
	}
}
w)/3)/x)/u)/e.com提供本手册内容,请勿盗用!

以上程序执行结果为:

字符串 Str1 长度 :13
字符串 Str2 长度 :5
w)/3)/x)/u)/e.com提供本手册内容,请勿盗用!

Java String类Java String类