- System.arraycopy()
arraycopy(Object src,int srcPos,Object dest,int destPos,int length)
param:
src: the source array.
srcPos: starting position in the source array.
dest: the destination array.
destPos: starting position in the destination data.
length: the number of array elements to be copied.
- 代码
public class TestCopy {
public static void main(String[] args) {
int[] array1 = {
1, 0, 0, 0, 1};
int[] array2 = new int[array1.length+2];
array2[0]=0;
array2[array1.length+1]=0;
System.arraycopy(array1,0,array2,1,array1.length);
System.out.println(Arrays.toString(array2)); //[0, 1, 0, 0, 0, 1, 0]
}
}