各种阵列复制方法的区别 [英] Difference between various Array copy methods

查看:311
本文介绍了各种阵列复制方法的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么


  • System.arraycopy()

  • 的clone()

  • 通过元素迭代手动复制

  • 和只是做 arraynew = arrayold

  • System.arraycopy(),
  • clone()
  • manual copying by iterating through the elements
  • and just doing 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 of clone 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 points arraynew to the memory address of arrayold or, in other words, you are simply assigning a reference to the old array.
  • 这篇关于各种阵列复制方法的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆