LinkedHashMap
extends HashMap<K,V> implements Map<K,V>
LinkedHashMap继承了HashMap,通过重写HashMap的插入访问的后置方法,实现了可以按照访问顺序排序的容器
-
容器实体
/**
* HashMap.Node subclass for normal LinkedHashMap entries.
* 变成了双向链表
*/
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);
}
}
/**
* The head (eldest) of the doubly linked list.
*/
transient LinkedHashMap.Entry<K,V> head;
/**
* The tail (youngest) of the doubly linked list.
*/
transient LinkedHashMap.Entry<K,V> tail;