描述
我们知道使用List的retainAll方法可以获取两个集合的交集,但是在某些情况下方法的返回值并非我们想象那样。
现象
先看两个例子: public static void main(String[] args) {List<String> a new ArrayList<>();a.add("READ&quo…
Java中取多个集合的交集
集合 Collection 接口中定义了 retainAll()方法
retainAll() Retains only the elements in this set that are contained in the specified collection (optional operation). In other words, removes from this set all of its elements that are …