使用Scanner从ArrayList到二维数组的java字符串
我正在使用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());
共 (0) 个答案