JAVA数组复制和扩容

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

数组的复制:

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]

原文地址:https://www.cnblogs.com/gangzi4321/p/12980830.html