代码改变世界

JAVA数组复制和扩容

2020-05-28 14:48  gangzi4321  阅读(296)  评论(0编辑  收藏  举报

有时候想要用一下数组的复制和扩容操作,记录一下:

数组的复制:

int[] a = {1,2,3,4,5};

int[] a1 = {4,5,6,7,8,9};

System.arraycopy(a,1,a1,0,4);

[2,3,4,5,8,9]


数组的扩容

int[] a =  {1,2,3,4,5};
a = Arrays.copy(a,a.length+1);

[1,2,3,4,5,0]