Skip to content

Commit 71d3fd9

Browse files
committed
💬 update LinkedHashMap
1 parent 9b7f246 commit 71d3fd9

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

MD/collection/LinkedHashMap.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,34 @@
3232
调试可以看到 `map` 的组成:
3333

3434
![](https://ws2.sinaimg.cn/large/006tKfTcly1fo6l9xp91lj319m0s4tgi.jpg)
35+
36+
37+
打开源码可以看到:
38+
39+
```java
40+
/**
41+
* The head of the doubly linked list.
42+
*/
43+
private transient Entry<K,V> header;
44+
45+
/**
46+
* The iteration ordering method for this linked hash map: <tt>true</tt>
47+
* for access-order, <tt>false</tt> for insertion-order.
48+
*
49+
* @serial
50+
*/
51+
private final boolean accessOrder;
52+
53+
private static class Entry<K,V> extends HashMap.Entry<K,V> {
54+
// These fields comprise the doubly linked list used for iteration.
55+
Entry<K,V> before, after;
56+
57+
Entry(int hash, K key, V value, HashMap.Entry<K,V> next) {
58+
super(hash, key, value, next);
59+
}
60+
}
61+
```
62+
63+
其中 `Entry` 继承于 `HashMap``Entry`,并新增了上下节点的指针,也就形成了双向链表。
64+
65+
还有一个 header 的成员变量,是这个双向链表的头结点。

0 commit comments

Comments
 (0)