如何从另一个列表中删除一个列表的重叠内容? [英] How do you remove the overlapping contents of one List from another List?
本文介绍了如何从另一个列表中删除一个列表的重叠内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
List<String> listA = new ArrayList<String>();
listA.add("a");
listA.add("b");
listA.add("c");
listA.add("d");
List<String> listB = new ArrayList<String>();
listB.add("c");
listB.add("d");
listB.add("e");
listB.add("f");
ListB
包含两个同样出现在 ListA
中的元素("c"
和 "d"
).
ListB
contains two elements that are also present in ListA
("c"
and "d"
).
是否有一种干净的方法可以确保 listB
不包含这些元素或任何其他可能已存在于 listA
中的重叠元素?
Is there a clean way to make sure that listB
does not contain these or any other overlapping elements that may already exist in listA
?
推荐答案
listB.removeAll(listA)
这将使您的 listB
只包含 [e, f]
.
This would make your listB
contain only [e, f]
.
这篇关于如何从另一个列表中删除一个列表的重叠内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文