💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] # 二维数组 ## 定义格式 * 数据类型[ ][ ] 数组名; * 数据类型 数组名[ ][ ]; 不推荐 * 数据类型[ ] 数组名[ ]; 不推荐 ## 初始化方式 A:动态初始化 > 数据类型[ ][ ] 变量名 = new 数据类型[m][n]; B:静态初始化 > 数据类型[ ][ ] 变量名 = new 数据类型[ ][ ]{{元素…},{元素…},{元素…}}; 简化版格式:数据类型[ ][ ] 变量名 = {{元素…},{元素…},{元素…}}; ## 二维数组的遍历 ``` for(int y=0;y<arr.length;y++){ for(int x=0;x<arr[y].length;x++){ System.out.println(arr[y][x]); } } ``` ## N维数组 ``` String [] string1 = {"a","b","c"}; String [] [] string2 = {{"a","b","c"},{"a","b","c"}}; String [][][] string3 = {{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}}; String [][][][] string4 = {{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}},{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}},{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}}}; String [][][][][] string5 = {{{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}},{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}},{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}}},{{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}},{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}},{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}}},{{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}},{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}},{{{"a","b","c"},{"a","b","c"}},{{"a","b","c"},{"a","b","c"}}}}}; for(int i = 0;i<string5.length;i++) { for(int j = 0;j<string5[0].length;j++) { for(int k = 0;k<string5[0][0].length;k++) { for(int m = 0;m<string5[0][0][0].length;m++) { for(int n = 0;n<string5[0][0][0][0].length;n++) { System.out.println(string5[i][j][k][m][n]); } } } } } ```