Collection:
Collection是层次结构中的根节点
其中List的子类都是有序的 Set和Queue的子类都是无序的
Set的子类不允许有重复的元素 Queue和List的子类是允许有重复的子类
所有Collection子类通用的方法:
增:
boolean add(Object obj) 确保集合中含有该元素,如果该集合允许有重复的元素,则可以插入。 如果集合发生了改变则返回True,否则返回False
boolean addAll(Collection c)
删:
void clear()
boolean remove(Object o) //该操作只会删除集合中第一个o
boolean removeAll(Collection<?> c) 例如A.removeAll(B) 的集合操作为 A-(A∩B)
boolean retainAll(Collection<?> c) A.retainAll(B)的集合操作为A∩B
查:
boolean contains(Object o)
boolean containsAll(Collection c)
遍历:
Iterator<E> iterator()
获取容器的属性:
size();
isEmpty();
和数组转换:
Object[] toArray()
改变集合结构的操作: 所有改变集合的操作如增删 如果集合改变了就返回true,没有改变就返回false
boolean addAll(Collection c)
boolean removeAll(Collection c) //如果原集合有有两个以上的“Hello”,c中有一个“Hello”,那么原集合中所有的“Hello”都会被删除。这和remove操作有所不同
boolean retainAll(Collection c) //此操作在集合运算中是交集∩