您好,欢迎来到品趣旅游知识分享网。
搜索
您的当前位置:首页LinkedHashMap部分源码

LinkedHashMap部分源码

来源:品趣旅游知识分享网

HashMap内部维护着节点数组.虽然利于查询,但是无序.

而LinkedHashMap却修改了节点,

节点本身在数组坐标上拥有查看下一个相同hash值的节点的能力(Node本身有next的属性),

static class Node<K,V> implements Map.Entry<K,V> {
        final int hash;
        final K key;
        V value;
        Node<K,V> next;

        Node(int hash, K key, V value, Node<K,V> next) {
            this.hash = hash;
            this.key = key;
            this.value = value;
            this.next = next;
        }
        。。。
        。。。
}

但LinkedHashMap又将所有的节点串成一串,给与了befor.after的属性

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

这样,linkedHashMap的节点数组就成了这样子。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- pqdy.cn 版权所有 赣ICP备2024042791号-6

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务