collection 知识点3

*Collection类中  带All的功能演示

boolean addAll(Collection c)      

例子: a.addAll(c)  表示将c中所有的元素添加进a中,并返回boolean值表示是否添加成功。

如果是 写成 a.add(c),则会把c以toString后的形态,添加至a中。


boolean removeAll(Collection c)

例子: a.removeAll(c)   表示从a中去掉c中出现的所有元素(与a取交集的元素)

boolean containsAll(Collection c)

例子:a.containsAll(c)  若a中包含c,则返回true ;并且a中不会添加c中的元素


boolean retainAll(Collection c)

a.retainAll(c)   交集的结果给a 

例子: 取交集,如果调用的集合改变,返回true;如果调用的集合没有改变,返回false

原文地址:https://www.cnblogs.com/fjwjw/p/9890314.html