往列表插入元素出错,错误描述和代码截图如下
创建数组,往数组里添加元素,然后把数组转换成List ,但是转换过来以后 List里面的所有元素都变成了数组里的最后一个元素 。
截图没发上,代码如下:
public void pokerAdd(){
System.out.println("~~~~~~~~~~创建扑克牌~~~~~~~~~~");
PokerGame[] pokerGame =
{new PokerGame("黑桃","2"),new PokerGame("黑桃","3"),new PokerGame("黑桃","4"),new PokerGame("黑桃","5"),new PokerGame("黑桃","6"),new PokerGame("黑桃","7"),new PokerGame("黑桃","8"),new PokerGame("黑桃","9"),new PokerGame("黑桃","10"),new PokerGame("黑桃","J"),new PokerGame("黑桃","Q"),new PokerGame("黑桃","K"),new PokerGame("黑桃","A")
,new PokerGame("红桃","2"),new PokerGame("红桃","3"),new PokerGame("红桃","4"),new PokerGame("红桃","5"),new PokerGame("红桃","6"),new PokerGame("红桃","7"),new PokerGame("红桃","8"),new PokerGame("红桃","9"),new PokerGame("红桃","10"),new PokerGame("红桃","J"),new PokerGame("红桃","Q"),new PokerGame("红桃","K"),new PokerGame("红桃","A")
,new PokerGame("梅花","2"),new PokerGame("梅花","3"),new PokerGame("梅花","4"),new PokerGame("梅花","5"),new PokerGame("梅花","6"),new PokerGame("梅花","7"),new PokerGame("梅花","8"),new PokerGame("梅花","9"),new PokerGame("梅花","10"),new PokerGame("梅花","J"),new PokerGame("梅花","Q"),new PokerGame("梅花","K"),new PokerGame("梅花","A")
,new PokerGame("方块","2"),new PokerGame("方块","3"),new PokerGame("方块","4"),new PokerGame("方块","5"),new PokerGame("方块","6"),new PokerGame("方块","7"),new PokerGame("方块","8"),new PokerGame("方块","9"),new PokerGame("方块","10"),new PokerGame("方块","J"),new PokerGame("方块","Q"),new PokerGame("方块","K"),new PokerGame("方块","A")
}; //创建牌组,插入52张牌
this.pokers = new ArrayList(Arrays.asList(pokerGame)); //将数组转换为List,并且插入pokers表中
System.out.println("~~~~~~~~~扑克牌创建成功~~~~~~~~~");
System.out.print("牌组为:");
for(PokerGame poker: pokers){
System.out.print(poker.getColor()+poker.getPoint());
System.out.print(" ");
}
System.out.println("");
}