烟台网站设计单位,如何帮别人推广赚钱,移动网站建站系统,企业网站如何提高Arrays.copyOf 和 System.arraycopy
1#xff09;二者有何不同#xff1f;
System.arraycopy()方法 System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length); 需主动创建目标对象dest可定义起始元素#xff0c;灵活拷贝元素比较重要的一点…Arrays.copyOf 和 System.arraycopy
1二者有何不同
System.arraycopy()方法 System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length); 需主动创建目标对象dest可定义起始元素灵活拷贝元素比较重要的一点native方法性能好
Arrays.copyOf()方法 Arrays.copyOf(Object[] original, int newLength) copyOf方法中调用了System.arraycopy()这个方法适合不创建目标对象的情况主动创建新数组 2深拷贝or 浅拷贝 只有一维数组且元素类型为 基本数据类型、包装类基本数据类型的 引用类型或String类时使用Arrays.copyOf 属于 深拷贝其他皆为浅拷贝 对于二维数组归为其他使用Arrays.copyOf 属于浅拷贝只拷贝了元素的地址。故当对拷贝后数据进行修改被拷贝对象的数据也就改变了。