System提供了一個靜態方法arraycopy(),我們可以使用它來實現數組之間的復制。其函數原型是:
public static native void arraycopy(Object src,int srcPos,Object dest, int destPos,int length);
* @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. 復制的長度
舉個栗子:
將array數組復制到新的數組中;
int[] array = {1, 2, 3, 4, 5};
int[] targetArr = new int[array.length];
System.arraycopy(array,0,targetArr,0,array.length);