system.arraycopy是複製數組中制定元素到目標數組,
arrays.copyof會創建一個新的數組,並調用了system.arraycopy,具體見源碼
public static int[] copyOf(int[] original, int newLength) {
int[] copy = new int[newLength];
System.arraycopy(original, 0, copy, 0,
Math.min(original.length, newLength));
return copy;
}
關鍵點,arrays.copyof會從創建一個新的數組,而system.arraycopy只是複製數組的功能,單獨的他不會創建新的數組。