1. 特点
-
继承HashMap
-
Entry继承HashMap的Node
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); } }
-
accessOrder:true访问顺序,false插入顺序,测试代码如下
public static void main(String[] args) { LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(0, 0.75f, true);// false map.put("1", "value1"); map.put("2", "value2"); map.put("3", "value3"); print(map); map.get("2"); //map.getOrDefault("2","default"); print(map); } accessOrder = true 1 value1 2 value2 3 value3 -------------------------------------- 1 value1 3 value3 2 value2 -------------------------------------- accessOrder