容器类大致分类示意图
(非精确分类)(绿色表示 interface,蓝色表示 class)
容器类类库划分
1、 Collection。一个独立元素的序列。这些元素都服从一条或多条规则。
List 必须按照插入顺序保存元素
Set 不能有重复元素
Queue 按照排队规则来确定对象产生的顺序
所有 Collection 都可以使用 foreach 遍历
Collection 在每个“槽”中只能保存一个元素
Collection 常用方法:
boolean add(E e)
Ensures that this collection contains the specified element (optional operation).
boolean addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this collection (optional operation).
void clear()
Removes all of the elements from this collection (optional operation).
boolean contains(Object o)
Returns true if this collection contains the specified element.
boolean containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection.
boolean equals(Object o)
Compares the specified object with this collection for equality.
int hashCode()
Returns the hash code value for this collection.
boolean isEmpty()
Returns true if this collection contains no elements.
Iterator<E> iterator()
Returns an iterator over the elements in this collection.
boolean remove(Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation).
int size()
Returns the number of elements in this collection.
2、Map。一组成对的“键值对”对象,允许使用 key 来查找 value。
Hash