我目前有一個隨機混合ArrayList
。Java-將元素從ArrayList移動到數組
public static void main(String[] args) {
ArrayList<Integer> solution = new ArrayList<>();
for (int i = 1; i <= 48; i++) {
solution.add(i);
}
Collections.shuffle(solution);
這給我一個ArrayList
與數字1-48隨機混合。現在我有4個數組,我想隨機添加ArrayList
的元素而不重複。
int[] heartsRow = new int[14];
int[] diamondsRow = new int[14];
int[] spadesRow = new int[14];
int[] clubsRow = new int[14];
新數組包含14個元素的原因是因爲前兩個元素總是相同。
heartsRow[0] = 1;
heartsRow[1] = 0;
diamondsRow[0] = 14;
diamondsRow[1] = 0;
spadesRow[0] = 27;
spadesRow[1] =0;
clubsRow[0] = 40;
clubsRow[1] = 0;
我想用ArrayList
的非重複元素完全填充每個陣列。