LinkedHashMap

LinkedHashMap既是一个HashMap,也是一个链表

package java.util;

import java.util.function.Consumer;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.io.IOException;

public class LinkedHashMap<K,V>
    extends HashMap<K,V>
    implements Map<K,V> {
    
    static class Entry<K,V> extends HashMap.Node<K,V> {
        // LinkedHashMap的每个Entry元素多了两个引用
        Entry<K,V> before, after;
        Entry(int hash, K key, V value, Node<K,V> next) {
            super(hash, key, value, next);
        }
    }
    // 第一个元素
    transient LinkedHashMap.Entry<K,V> head;
    // 最后一个元素
    transient LinkedHashMap.Entry<K,V> tail;
}

// HashMap.Node
static class Node<K,V> implements Map.Entry<K,V> {
    final int hash;
    final K key;
    V value;
    Node<K,V> next;
}
原文地址:https://www.cnblogs.com/Mike_Chang/p/10428764.html