【发布时间】:2023-04-05 15:44:01
【问题描述】:
我正在使用 Eclipse,我正在尝试获取一个字符串:
1 2 3 4
在 ArrayList 之外:
ArrayList strings = new ArrayList<>();
并将每个数字存储到一个二维数组中:
int size = (int) strings.get(0); // Represents the number of rows
int stringList[][] = new int[size][];
// Store results in a two dimensional array
for(int i = 0; i < size; i++){
int index = i + 1;
String fish = (String) strings.get(index);
Scanner npt = new Scanner(fish);
for(int j = 0; npt.hasNext(); j++) {
size[i][j] = Integer.parseInt(npt.next());
}
}
这是导致错误的部分:
// ERROR: The type of the expression must be an array type but it resolved to int
size[i][j] = Integer.parseInt(npt.next());
【问题讨论】:
-
size是int,你不能写size[i][j]。错误信息很清楚。 -
哇,我必须完全摆脱它,我根本没有注意到这一点。很抱歉浪费了你们的时间。
标签: java arrays string loops int