为了账号安全,请及时绑定邮箱和手机立即绑定

应该怎么插入元素到列表中,我这种方法哪里出错了?

应该怎么插入元素到列表中,我这种方法哪里出错了?

温柔的晚风 2016-07-26 17:26:42
 创建数组,往数组里添加元素,然后把数组转换成List 。但是转换过来以后 List里面的所有元素都变成了数组里的最后一个元素。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张牌      List<PokerGame> pokers = Arrays.asList(pokerGame);     this.pokers = new ArrayList(Arrays.asList(pokerGame)); //将数组转换为List,并且插入pokers表中      System.out.println("~~~~~~~~~扑克牌创建成功~~~~~~~~~");       System.out.print("牌组为:");      for(int h=0;h<(pokerGame.length - 1);h++){      PokerGame poker =(PokerGame)pokers.get(h);          System.out.print(poker.color+poker.point);         System.out.print(" ");
查看完整描述

2 回答

?
温柔的晚风

TA贡献1条经验 获得超0个赞

为什么我上传了图片,在问题中却看不到?

查看完整回答
反对 回复 2016-07-26
  • 2 回答
  • 0 关注
  • 1365 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信