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]
posted @ 2022-04-07 20:40  启豪  阅读(41)  评论(0编辑  收藏  举报