java使用array是copyof创建新长度数组
Arrays.copyof()
int[] copied = Arrays.copyOf(arr, 10); //10 the the length of the new array System.out.println(Arrays.toString(copied)); copied = Arrays.copyOf(arr, 3); System.out.println(Arrays.toString(copied));
运行结果:
[1, 2, 3, 4, 5, 0, 0, 0, 0, 0] [1, 2, 3]