Java length() 方法
length() 方法用于返回字符串的長度。
長度等于字符串中 16 位 Unicode 代碼單元的數(shù)量。
語法
public int length()
參數(shù)
- 無
返回值
返回字符串長度。
實例
public class Test { public static void main(String args[]) { String Str1 = new String("www.o2fo.com"); String Str2 = new String("youj" ); System.out.print("字符串 Str1 長度 :"); System.out.println(Str1.length()); System.out.print("字符串 Str2 長度 :"); System.out.println(Str2.length()); } }
以上程序執(zhí)行結(jié)果為:
字符串 Str1 長度 :14 字符串 Str2 長度 :6
更多建議: