1.ArrayList
數組
transient Object[] elementData;
private static final int DEFAULT_CAPACITY = 10;
2.LinkedList
雙向循環列表
transient Node<E> first;
transient Node<E> last;
private static class Node<E> {
E item;
Node<E> next;
Node<E> prev;
}
3.HashMap
數組和鏈表,超過8(含)鏈表會變成紅黑樹,少於6(含)重新變成鏈表
transient Node<K,V>[] table;
static final int DEFAULT_INITIAL_CAPACITY = 1 << 4;//16
static class Node<K,V> implements Map.Entry<K,V> {
final int hash;
final K key;
V value;
Node<K,V> next;
}
4.LinkedHashMap
以HashMap維護數據結構,以LinkList的方式維護數據插入順序
transient LinkedHashMap.Entry<K,V> head;
static class Entry<K,V> extends HashMap.Node<K,V> {
Entry<K,V> before, after;
Entry(int hash, K key, V value, Node<K,V> next) {
super(hash, key, value, next);
}
}
static class Node<K,V> implements Map.Entry<K,V> {
final int hash;
final K key;
V value;
Node<K,V> next;
}
5.TreeMap
基於紅黑樹實現
private transient Entry<K,V> root;
static final class Entry<K,V> implements Map.Entry<K,V> {
K key;
V value;
Entry<K,V> left;
Entry<K,V> right;
Entry<K,V> parent;
boolean color = BLACK;
}