数组的length属性,与String的length()方法

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

猜你喜欢

转载自blog.csdn.net/li1593891525/article/details/121404040