list采坑记录一下

Posted michaelcnblogs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了list采坑记录一下相关的知识,希望对你有一定的参考价值。

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采坑记录一下的主要内容,如果未能解决你的问题,请参考以下文章

Redis采坑记录

Knife4j学习采坑记录

Android Studio采坑记录

springboot单元测试采坑记录

Mac使用Gradle上传jar到中央仓库(最完整的采坑记录)

jumserver 3.0安装及采坑记录