list中的add()方法怎么一直只替换第一个数组啊?
public void Shuffle(){
System.out.println("请洗牌!");
Set<Card> cards1=new HashSet<Card>(cards);
cards=new ArrayList<Card>(cards1);
System.out.println("洗牌完成,请发牌!");
Player player1=new Player();
Player player2=new Player();
player1=players.get(0);
player2=players.get(1);
for(int i=0;i<4;i++){
Card cd1=cards.get(i);
int n=i%2;
switch(n){
case 0:
player1.getCards().add(cd1);
System.out.println(player1.getName()+"获得的牌为:"+cd1.getColour()+cd1.getName());
continue;
case 1:
player2.getCards().add(cd1);
System.out.println(player2.getName()+"获得的牌为:"+cd1.getColour()+cd1.getName());
continue;
}
}
}
每次for循环都是把原来的给替换而不是在list序列后继续添加怎么回事啊?