src:原始数组,srcPos:原始数组索引位置,dest:目标数组,destPos:目标数组的索引位置,length:拷贝个数
System.arraycopy(src, srcPos, dest, destPos, length);
package com.guor.test.javaSE.collection;
import java.util.Arrays;
import com.guor.test.User;
public class ArrayTest {
public static void main(String[] args) {
beanCopy();
}
//**************************************************************
private static void copySelf() {
int[] ids = { 1, 2, 3, 4, 5 };
System.out.println(Arrays.toString(ids));
//System.arraycopy(src, srcPos, dest, destPos, length);
// 把从索引0开始的2个数字复制到索引为3的位置上
System.arraycopy(ids, 0, ids, 3, 2);
System.out.println(Arrays.toString(ids));//[1, 2, 3, 1, 2]
}
private static void copyToOther() {
int[] ids = { 1, 2, 3, 4, 5 };
//将数据的索引1开始的3个数据复制到目标的索引为0的位置上
int[] other = new int[5];
System.arraycopy(ids, 1, other, 0, 3);
System.out.println(Arrays.toString(ids));//[1, 2, 3, 4, 5]深复制
System.out.println(Arrays.toString(other));//[2, 3, 4, 0, 0]
}
}
System.arraycopy 总结
基本数组属于深copy:改变原始数组或者copy数组,另一个数组对应的引用对象值不变
多维数组和数组对象是浅copy:(改变原始数组或者copy数组,另一个数组对应的引用对象值一起改变



