我正在尝试将字母序列作为字符串添加到二维数组中。所以object [17]
转到endState[0][0]
; [18]
到 endState[0][1]
等等。
我遇到的问题是外部 for 循环,它只是将 [32]
处的对象添加到矩阵中的所有单元格。通常,在使用其他集合时,我会使用迭代器来处理这个问题,但是,据我所知,使用数组是不可能的(正如您可能已经猜到的那样,我是一个新手)。
String [][] endState = new String[4][4];
for(int i1=17;i1<33;i1++){
for(int r=0;r<endState.length;r++){
for(int c=0;c<endState.length;c++){
endState[r][c] = config.split("")[i1];
}
}
}
关于如何克服这个问题有什么建议吗?
非常感谢。
最佳答案
你需要这样的东西吗?
String[] configs = config.split("");
String [][] endState = new String[4][4];
int i = 17;
for(int r=0;r<endState.length;r++){
for(int c=0;c<endState.length;c++){
endState[r][c] = configs[i++];
}
}
关于java - 数组是否有类似迭代器的函数(或解决方法)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42078339/