各种阵列复制方法的区别 [英] Difference between various Array copy methods
本文介绍了各种阵列复制方法的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是什么
-
System.arraycopy()
, -
的clone()
- 通过元素迭代手动复制
- 和只是做
arraynew = arrayold
?
System.arraycopy()
,clone()
- manual copying by iterating through the elements
- and just doing
arraynew = arrayold
?
推荐答案
-
System.arraycopy()
使用JNI(Java本地接口)复制
一个数组(或它的一部分),所以它是
极快的,你可以确认
这里; -
的clone()
创建一个新阵列具有相同特征的旧的阵列,即相同的大小,相同类型和同的内容。请参考这里 为在行动克隆
; -
手动复制
,没错,是手动复制。没有太多的话要说,该方法相同,只是很多人都认为它是最高性能。 -
arraynew = arrayold
不复制数组;它只是百分点的arraynew
来的内存地址arrayold
或者,换句话说,你只是分配的参考以旧数组。
System.arraycopy()
uses JNI (Java Native Interface) to copy an array (or parts of it), so it is blazingly fast, as you can confirm here;clone()
creates a new array with the same characteristics as the old array, i.e., same size, same type, and same contents. Refer to here for some examples ofclone
in action;manual copying
is, well, manual copying. There isn't much to say about this method, except that many people have found it to be the most performant.arraynew = arrayold
doesn't copy the array; it just pointsarraynew
to the memory address ofarrayold
or, in other words, you are simply assigning a reference to the old array.
这篇关于各种阵列复制方法的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文