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()方法:效率最差方法

相关文章
相关标签/搜索