System 类中:数组拷贝的方法:
public static native void arraycopy(Object src,int srcPos,Object dest,int destPos,int length);
参数:
src:源数组
srcPos:原数组中的起始位置
dest:目标数组
destPos:目标数组中的起始位置
length:要复制的数组元素的数量
示例代码:
int[] arr = { 1, 2, 3, 4, 5, 6 };
int[] arr2 = new int[5];
System.arraycopy(arr, 1, arr2, 2, 3);
System.out.println(arr2);
for(int i: arr2)
System.out.print(i+",");
输出结果:
0,0,2,3,4,