在二维数组中,我可以很容易地获取行的数组,我怎样才能将列也作为数组获取呢?我需要一个适用于对象的解决方案,而不仅仅是基元。谢谢
int counter = 1;
int[][] matrix = new int[9][9];
for (int x = 0; x < matrix.length; x++) {
for (int y = 0; y < matrix[0].length; y++) {
matrix[x][y] = counter;
System.out.print(counter + " ");
counter++;
}
System.out.println();
}
for (int x = 0; x < matrix.length; x++) {
int[] row = matrix[x];
}
原文由 Pedro Gonzalez 发布,翻译遵循 CC BY-SA 4.0 许可协议
没有“开箱即用”的方式,但您可以为此创建一个静态方法: