这个System.arraycopy其实底层逻辑本质和Arrays.copyOf是一样的
分析源码可以得出Arrays.copyOf也会走到System.arraycopy这个方法
下面是对参数的具体解读
/**
* @author 徐云鹏
* 仅供学习交流!
*/
public class System_ {
public static void main(String[] args) {
int arr1[] = {1, 6, 8};
int arr2[] = new int[3];
System.arraycopy(arr1, 0, arr2, 0, 3);
/**
* 解读--
* * @param src the source array.
* * @param srcPos starting position in the source array.
* * @param dest the destination array.
* * @param destPos starting position in the destination data.
* * @param length the number of array elements to be copied.
* 这五个参数是源码中给到的,通过分析可得出
* 第一个src即为需要传递的数组,就是要复制的数组
* 第二个secPos代表从src的哪一个(下标)元素开始传递
* dest代表要被传递(复制到的数组)到的数组
* destPos代表从dest哪一个(下标)元素开始接收
* length代表从源数组拷贝多少个数据到新数组 src --> dest*/
}
}
注意--
数组的拷贝长度是有范围的 如果超出了,会报数组越界异常ArrayIndexOutOfBoundsException