1、任何类型的数组(如char、int类型),都有length属性。
class Test {
public static void main(String[] args) {
int[] a = new int[10];
System.out.println(a.length);
}
}
输出:
10
Process finished with exit code 0
2、String的length()方法
class Test {
public static void main(String[] args) {
String s = "哈哈哈";
System.out.print(s.length());
}
}
输出:
3
Process finished with exit code 0