2014-01-17 73 views
1

這可能太愚蠢的問題,但我不能弄明白。使用這種ATM如何定義半全多維數組?

private static String[][][] ns=new String[][][]{{{"52","14",""},{"90","34",""},{"","",""}},{{"89","",""},{"67","78",""},{"","",""}},... 

其餘元件是{ 「」, 「」, 「」} ..所以陣列納秒必須是納秒[10] [3] [3]。我怎樣才能定義這個而不是寫所有{「」,「」,「」} ...?

回答

0

只是不要通過new T[] {}初始化您的數組。

String[][][] ns = new String[10][3][3]; 
for (int i = 0; i < ns.length; i++) { 
    for (int j = 0; j < ns[i].length; j++) { 
     for (int k = 0; k < ns[i][j].length; k++) { 
      ns[i][j][k] = ""; 
     } 
    } 
} 

ns[0][0][0] = "52"; 
ns[0][0][1] = "14"; 

ns[0][1][0] = "90"; 
ns[0][1][1] = "34"; 

ns[0][3][0] = "89"; 

ns[0][4][0] = "67"; 
ns[0][4][1] = "78";