Java中實現複製數組的幾種方法

一、for循環逐一複製;數據多的時候,複製速度會變慢。源碼

二、System.arraycopy()方法:效率最好for循環

三、Arrays.copyOf()方法:源碼以下效率

public static byte[] copyOf(byte[] original, int newLength) {
        byte[] copy = new byte[newLength];
        System.arraycopy(original, 0, copy, 0,
                         Math.min(original.length, newLength));
        return copy;
    }循環

四、clone()方法:效率最差方法

相關文章
相關標籤/搜索