/**
* 三、洗牌(Shuffle)
* @param args
*/
public void shuffle(){
System.out.println("------------开始洗牌...---------------");
Collections.shuffle(cardsToSelect);//这句是什么意思
System.out.println("------------洗牌结束-------------");
//测试是否洗牌成功,同时给元素分配id
int i = 0;
for (Cards cards : cardsToSelect) {
cards.id = i;
//System.out.println(cards.id+":"+cards.name);
i++;
}
}
3 回答

大咪
TA貢獻(xiàn)785條經(jīng)驗(yàn) 獲得超332個(gè)贊
????@Test ????public?void?shuffle(){ ???????? ????????List<Integer>?cardsToSelect?=?new?ArrayList<Integer>(); ????????cardsToSelect.add(1); ????????cardsToSelect.add(2); ????????cardsToSelect.add(3); ????????cardsToSelect.add(4); ????????for?(Integer?integer?:?cardsToSelect)?{ ????????????System.out.print("洗牌之前的集合值:"?+?integer?+?"??"); ????????} ????????System.out.println(); ????????System.out.println("------------開始洗牌...---------------"); ????????Collections.shuffle(cardsToSelect);//這句是什么意思 ???????? ????????for?(Integer?integer?:?cardsToSelect)?{ ????????????System.out.print("洗牌之后的集合值:"?+?integer?+?"??"); ????????} ????????System.out.println(); ????????System.out.println("------------洗牌結(jié)束-------------"); ????}

大咪
TA貢獻(xiàn)785條經(jīng)驗(yàn) 獲得超332個(gè)贊
shuffle洗牌的意思,他是Collections這個(gè)工具類的一個(gè)方法,見名知意,Collections.shuffle()
對括號(hào)中的集合進(jìn)行隨機(jī)打亂原來的順序,也就是跟洗牌似的
添加回答
舉報(bào)
0/150
提交
取消