Java中集合框架的整体体系如下:
【来源:https://www.processon.com/view/616d69c3e0b34d7c7dba91f7?fromnew=1】
可以大致分为两个部分,一个是单个数据的存储结构,其最顶层接口为Collection;一个是键值对的存储结构,其最顶层的接口是Map。
Collection
Collection是Java集合框架中所有线性集合的接口,这里的线性集合包括List、Queue、Set。其定义了与线性集合相关的常见的操作。
public interface Collection<E> extends Iterable<E> {
// 添加元素
boolean add(E e);
// 批量添加元素
boolean addAll(Collection<? extends E> c);
// 移除元素
boolean remove(Object o);
// 批量移除元素
boolean removeAll(Collection<?> c);
// 获取集合的大小
int size();
// 集合是否为空
boolean isEmpty();
// 是否包含某个元素
boolean