1 /* 2 如何获取数组的长度,格式: 3 数组名称.length 4 5 这将会得到一个int数字,代表数组的长度。 6 7 数组一旦创建,程序运行期间,长度不可改变。 8 */ 9 public class Demo03ArrayLength { 10 11 public static void main(String[] args) { 12 int[] arrayA = new int[3]; 13 14 int[] arrayB = {10, 20, 30, 3, 5, 4, 6, 7, 8, 8, 65, 4, 44, 6, 10, 3, 5, 4, 6, 7, 8, 8, 65, 4}; 15 int len = arrayB.length; 16 System.out.println("arrayB数组的长度是:" + len); 17 System.out.println("============="); 18 19 int[] arrayC = new int[3]; 20 System.out.println(arrayC.length); // 3 21 arrayC = new int[5]; 22 System.out.println(arrayC.length); // 5 23 //这个是正确的,因为相当于创建了两个数组 24 } 25 26 }
原文:https://www.cnblogs.com/zrwx/p/13767653.html