在java中按值复制数组 [英] copying array by value in java
本文介绍了在java中按值复制数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图制作一个数组的独立副本,但无法获得一个。看到我不能使用for循环将整数整数复制,因为效率原因。还有别的办法吗?
这是我的代码:
I tried to make an independent copy of an array but couldnt get one. see i cannot copy it integer by integer using a for loop because of efficiency reasons. Is there any other way? This was my code:
int[] temp = new int[arr.length];
temp = arr;
推荐答案
看看 System.arraycopy()
方法。比如,
Look at System.arraycopy()
method. Like,
int[] b = new int[a.length];
System.arraycopy(a, 0, b, 0, a.length);
这篇关于在java中按值复制数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文