相关疑难解决方法(0)

什么更有效:System.arraycopy或Arrays.copyOf?

Bloch中的toArray方法ArrayList使用System.arraycopyArrays.copyOf复制数组.

public <T> T[] toArray(T[] a) {
    if (a.length < size)
        // Make a new array of a's runtime type, but my contents:
        return (T[]) Arrays.copyOf(elementData, size, a.getClass());
    System.arraycopy(elementData, 0, a, 0, size);
    if (a.length > size)
        a[size] = null;
    return a;
}
Run Code Online (Sandbox Code Playgroud)

如何比较这两种复制方法以及何时应该使用哪种方法?

java arrays performance

72
推荐指数
5
解决办法
6万
查看次数

标签 统计

arrays ×1

java ×1

performance ×1