3 回答
TA贡献1789条经验 获得超10个赞
arr[i][j][k]
((arr[i])[j])[k]
arr
声明:
int[][][] threeDimArr = new int[4][5][6];
int[][][] threeDimArr = { { { 1, 2 }, { 3, 4 } }, { { 5, 6 }, { 7, 8 } } };
准入:
int x = threeDimArr[1][0][1];
int[][] row = threeDimArr[1];
字符串表示:
Arrays.deepToString(threeDimArr);
"[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]"
TA贡献1809条经验 获得超8个赞
您可以声明多维数组如下:
// 4 x 5 String arrays, all Strings are null
// [0] -> [null,null,null,null,null]
// [1] -> [null,null,null,null,null]
// [2] -> [null,null,null,null,null]
// [3] -> [null,null,null,null,null]
String[][] sa1 = new String[4][5];
for(int i = 0; i < sa1.length; i++) { // sa1.length == 4
for (int j = 0; j < sa1[i].length; j++) { //sa1[i].length == 5
sa1[i][j] = "new String value";
}
}
// 5 x 0 All String arrays are null
// [null]
// [null]
// [null]
// [null]
// [null]
String[][] sa2 = new String[5][];
for(int i = 0; i < sa2.length; i++) {
String[] anon = new String[ /* your number here */];
// or String[] anon = new String[]{"I'm", "a", "new", "array"};
sa2[i] = anon;
}
// [0] -> ["I'm","in","the", "0th", "array"]
// [1] -> ["I'm", "in", "another"]
String[][] sa3 = new String[][]{ {"I'm","in","the", "0th", "array"},{"I'm", "in", "another"}};
添加回答
举报