[英]Assigning part of an array in Java
I want to fill in part of an array with the values of another array. 我想用另一个数组的值填充数组的一部分。 Is there anyway I can do this without looping?
无论如何,我可以不循环执行此操作吗?
eg 例如
int [] [] ArrayToFillIn = new int [3] [3]
int [] FillingArray = {1, 2};
for (int i = 1; i < 3; i++)
{
ArrayToFillIn [i-1] [2] = FillingArray [i - 1];
}
in R it would be like: 在R中,它将像:
ArrayToFillIn [c(1:2),3] = FillingArray []
(considering that R does not start from 0) (考虑到R不是从0开始)
Thanks! 谢谢!
Sure. 当然。 Without a loop it would be
没有循环就会
ArrayToFillIn [0] [2] = FillingArray [0];
ArrayToFillIn [1] [2] = FillingArray [1];
What with this initialization: 这个初始化怎么办:
int [] FillingArray = {1, 2};
int [][] ArrayToFillIn = new int[][]{{0, 0, FillingArray[0]}, {0, 0, FillingArray[1]}, {}};
//---------------------------------------------^-----------------------^----------------^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.