package java03; /* *如何获取数组长度 : * 格式: * 数组名称.length * * 这会得到一个int数字,代表数组的长度 * * 数组一旦创建,程序运行期间,长度不可改变 * * */ public class Demo04ArrayLength { public static void main(String[] args) { int[] arrayA = new int[3]; int[] arrayB = {1,2,3,4,5,96,48,14,20,77,5,66,44,122,36,47,222,95,46,485,123}; int len = arrayB.length; System.out.println("arrayB数组的长度是: "+ len);//21 System.out.println("================="); int[] arrayC = new int[3]; System.out.println(arrayC.length);//3 arrayC = new int[5]; System.out.println(arrayC.length);//5 } }