老的方法和新的方法相比,是功能少呢还是支持的类型少?新的方法优点在哪里?

解决方案 »

  1.   

    底层还是调用的System.arraycopy,只不过新的方法更好理解,新的内容用返回值来表示,System.arraycopy的所有的内容都是在参数中指定,当然这样也增加了灵活性,可以自己指定目标数组
      

  2.   

    是Arrays.copyOf吧,这个方法将复制的数组元素加入到新的数组中,也就是这个方法会创建新的数组System.arrayCopy 不生成新数组,只是将复制元素加入已经存在的数组中其实Arrays.copyOf里面也是调用了System.arrayCopy的。
      

  3.   


    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;
        }开辟了新的数组,还是调用System.arraycopy
      

  4.   

    其实Arrays.copyOf的方法里还是调用了System.arraycopy的,本质是一样的。 
    个人觉得把放在Arrays里,使得关于数组操作都放在一个类(Arrays)里,方便大家记忆和使用。