静态初始化:创建+赋值
动态初始化:包含默认初始化
package array; import java.lang.reflect.Array; import java.util.Arrays; public class Demo01 { public static void main(String[] args) { int[] a=new int[10]; System.out.println(a); System.out.println(Arrays.toString(a)); Arrays.fill(a,10); System.out.println(Arrays.toString(a)); Arrays.fill(a,2,5,99); System.out.println(Arrays.toString(a)); } }
输出
[I@1b6d3586 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] [10, 10, 99, 99, 99, 10, 10, 10, 10, 10]