Collection是所有单列集合的父接口,因此在Collection中定义了单列集合(List和Set)通用的一些方法,这些方法可用于操作所有的单列集合。
Collection接口的方法
方法声明 | 功能描述 |
boolean add (Object o) | 向集合中添加一个元素 |
boolean addAll(Collection c) | 将指定Collection中的所宥元素添加到该集合中 |
void clear() | 刪除该集合中的所有元索 |
boolean remove( Object o) | 删除该集合中指定的元素 |
boolean removeAll(Collection c) | 刪除指定集合中的所有元素 |
boolean isEmpty() | 判断该集合是否为空 |
boolean contains(Object o) | 判断该集合中是押包含某个元素 |
boolean contains All(Collection c) | 判断该集合中是押包含指定集合屮的所有元素 |
Iterator iterator() | 返回在该集合的元索上进行迭代的迭代器(Iterator),用于遍历该集合所有元素 |
int size() | 获取该集合元素个数 |