码迷,mamicode.com
首页 > 其他好文 > 详细

list采坑记录一下

时间:2019-09-21 21:25:47      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:img   add   integer   集合   info   image   nbsp   print   copy   

List<Integer> cards = Lists.newArrayList(6,10,11,12,21,23,29,30,38,39,42,43,46,51,53,59,60);
List<Integer> copyList = Lists.newArrayList();
copyList = cards;
copyList.remove(2);
System.out.println("cards:"+cards);
System.out.println("copyList:"+copyList);


用了等号的操作结果是

cards:[6, 10, 12, 21, 23, 29, 30, 38, 39, 42, 43, 46, 51, 53, 59, 60]
copyList:[6, 10, 12, 21, 23, 29, 30, 38, 39, 42, 43, 46, 51, 53, 59, 60]

 

技术图片

 

 

 

List<Integer> cards = Lists.newArrayList(6,10,11,12,21,23,29,30,38,39,42,43,46,51,53,59,60);
List<Integer> copyList = Lists.newArrayList();
copyList.addAll(cards);
copyList.remove(2);
System.out.println("cards:"+cards);
System.out.println("copyList:"+copyList);


用了add的结果

cards:[6, 10, 11, 12, 21, 23, 29, 30, 38, 39, 42, 43, 46, 51, 53, 59, 60]
copyList:[6, 10, 12, 21, 23, 29, 30, 38, 39, 42, 43, 46, 51, 53, 59, 60]

 

技术图片

 

 

用等号操作时两个集合都会被操作,add不会

 

list采坑记录一下

标签:img   add   integer   集合   info   image   nbsp   print   copy   

原文地址:https://www.cnblogs.com/michaelcnblogs/p/11564438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!