copyOf函数:把原数组中的数据复制到新数组中,属于深层拷贝。
在复制时会自动创建一个新数组,再调用arraycopy函数复制原数组
中的数据到新数组中。
src:原数组
srcpro:复制的起始索引
dest:目标数组
destPos:复制到目标数组的起始位置
length:复制的长度
public static native void arraycopy(Object src, int srcPos,
Object dest, int destPos,
int length);
public static int[] copyOf(int[] original, int newLength) {
int[] copy = new int[newLength];
System.arraycopy(original, 0, copy