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;
}