2015-02-07 76 views
0

所以我創建了兩個數組和一個arrayList。根據遊戲的值(0或1),我希望我的arrayList具有我的一個數組的所有值。這是我一直在嘗試的添加一個數組到ArrayList

int[] americanBoard = {0,28,9,26,30,11,7,20,32,17,5,22,34,15,3,24,36,13,1,00,27,10,25,29,12,8,19,31,18,6,21,33,16,4,23,35,14,2}; 
int[] europeanBoard = {0,32,15,19,4,21,2,25,17,34,6,27,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26}; 
ArrayList<Integer[]> board = new ArrayList<Integer[]>(); 
(game>0? board.add(americanBoard): board.add(europeanBoard)); 

感謝您的幫助!

+0

此問題已被解答[這裏](http://stackoverflow.com/questions/157944/create-arraylist-arraylistt-from-array-t) – 2015-02-07 03:45:49

回答

2

你可以改變你的陣列類型Integer,然後使用Arrays.asList方法:

 Integer[] americanBoard = {0,28,9,26,30,11,7,20,32,17,5,22,34,15,3,24,36,13,1,00,27,10,25,29,12,8,19,31,18,6,21,33,16,4,23,35,14,2}; 
     Integer[] europeanBoard = {0,32,15,19,4,21,2,25,17,34,6,27,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26}; 
     ArrayList<Integer> board = new ArrayList<Integer>(Arrays.asList((game>0? americanBoard: europeanBoard))); 

可以在Javadocs找到有關該方法的詳細信息:

返回支持的固定大小的列表由指定的數組。

+0

這似乎工作。非常感謝! – Harbus 2015-02-07 03:57:38

相關問題