length() 方法用于返回字符串的长度。
长度等于字符串中 16 位 Unicode 代码单元的数量。
public int length()
返回字符串长度。
public class Test {
public static void main(String args[]) {
String Str1 = new String("www.jb51.net");
String Str2 = new String("jb51" );
System.out.print("字符串 Str1 长度 :");
System.out.println(Str1.length());
System.out.print("字符串 Str2 长度 :");
System.out.println(Str2.length());
}
}
以上程序执行结果为:
字符串 Str1 长度 :12 字符串 Str2 长度 :4
在线实例
字符集 & 工具
最新更新
站点信息
Java String类