LinkedHashMap的内部实现与HashMap实现有什么不同? [英] How is the internal implementation of LinkedHashMap different from HashMap implementation?
问题描述
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' →入口→入口←链表实现
[入口]
[入口]→入口
[入口]
[null]
因此,它有一个Entry对象数组。
问题:
-
我在想,如果这个数组的索引在同一个hashCode但是不同的对象的情况下存储多个Entry对象,它该如何存储。
-
这与
LinkedHashMap
实现有何不同?它的映射的双向链表实现,但它是否像上面那样维护一个数组,并且它如何存储指向下一个和上一个元素的指针?
因此,它有一个 Entry
对象的数组。
不完全。它有一个 Entry
对象链的数组。一个 HashMap.Entry
对象有一个下一个
字段,允许 Entry
$ b
我想知道该数组的索引如何存储多个
条目
对象在相同的hashCode但不同的对象的情况下。
因为(如问题中的图片所示)条目
对象被链接。
这与
LinkedHashMap
实现有何不同?它的映射的双向链表实现,但它是否像上面那样维护一个数组,并且它如何存储指向下一个和上一个元素的指针?
通过主散列数组访问的单链接哈希链,以及保存在条目中的所有条目的单独双向链接列表 I read that HashMap has the following implementation: So, it has an array of Entry objects. Questions: I was wondering how can an index of this array store multiple Entry objects in case of same hashCode but different objects. How is this different from
So, it has an array of Not exactly. It has an array of I was wondering how can an index of this array store multiple Because (as the picture in your question shows) the How is this different from In the a singly linked hash chain that is accessed via the main hash array, and a separate doubly linked list of all entries that is kept in entry insertion order. 这篇关于LinkedHashMap的内部实现与HashMap实现有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<在 LinkedHashMap
实现中, LinkedHashMap.Entry
类扩展了 HashMap.Entry
类,在和之后的
字段中添加。这些字段用于将
LinkedHashMap.Entry
对象组合成独立的双向链接列表,用于记录插入顺序。因此,在 LinkedHashMap
类中,入口对象有两个不同的链:
广告订单。
main array
↓
[Entry] → Entry → Entry ← linked-list implementation
[Entry]
[Entry] → Entry
[Entry]
[null ]
LinkedHashMap
implementation? Its doubly linked list implementation of map but does it maintain an array like the above and how does it store pointers to the next and previous element?
Entry
objects.Entry
object chains. A HashMap.Entry
object has a next
field allowing the Entry
objects to be chained as a linked list.
Entry
objects in case of same hashCode but different objects.Entry
objects are chained.
LinkedHashMap
implementation? Its doubly linked list implementation of map but does it maintain an array like the above and how does it store pointers to the next and previous element?LinkedHashMap
implementation, the LinkedHashMap.Entry
class extends the HashMap.Entry
class, by adding before
and after
fields. These fields are used to assemble the LinkedHashMap.Entry
objects into an independent doubly-linked list that records the insertion order. So, in the LinkedHashMap
class, the entry objects are in two distinct chains: