LinkedHashMap
概述
LinkedHashMap数据结构相比较于HashMap来说,添加了双向指针,分别指向前一个节点——before和后一个节点——after,从而将所有的节点已链表的形式串联一起来
//HashMap里面的方法在LinkedHashMap进行了重写
void afterNodeAccess(Node<K,V> p) { }
void afterNodeInsertion(boolean evict) { }
void afterNodeRemoval(Node<K,V> p) { }
Entry节点类
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);
}
}
继承HashMap的node节点增加了before和after两个指针。
类属性
// 用于指向双向链表的头部
transient LinkedHashMap.Entry<K,V> head;
//用于指