本文介绍了最好的办法复制从一个阵列到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行下面的code,没有被复制? - 我在做什么错
此外,这是最好的/最有效的方式从一个数组复制到另一个数据?
公共类A {
公共静态无效的主要(字符串ARGS []){
诠释一个[] = {1,2,3,4,5,6};
INT B〔] =新的INT [则为a.length]; 的for(int i = 0; I<则为a.length;我++){
一个由[i] = B [I];
}
}
}
解决方案
我觉得你的任务是倒退:
A [i] = B [I];
应该是:
B [I] = a [i];
When I run the following code, nothing gets copied - what am I doing wrong?
Also, is this the best/most efficient way to copy data from one array to another?
public class A {
public static void main(String args[]) {
int a[] = { 1, 2, 3, 4, 5, 6 };
int b[] = new int[a.length];
for (int i = 0; i < a.length; i++) {
a[i] = b[i];
}
}
}
解决方案
I think your assignment is backwards:
a[i] = b[i];
should be:
b[i] = a[i];
这篇关于最好的办法复制从一个阵列到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!