Skip to content

Commit 1a7249d

Browse files
authored
Update hashmap-source-code.md
改动行数265 将put流程图更新,地址是用的阿里云oss
1 parent f69d399 commit 1a7249d

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

docs/java/collection/hashmap-source-code.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,8 @@ HashMap 只提供了 put 用于添加元素,putVal 方法只是给 put 方法
262262
1. 如果定位到的数组位置没有元素 就直接插入。
263263
2. 如果定位到的数组位置有元素就和要插入的 key 比较,如果 key 相同就直接覆盖,如果 key 不相同,就判断 p 是否是一个树节点,如果是就调用`e = ((TreeNode<K,V>)p).putTreeVal(this, tab, hash, key, value)`将元素添加进入。如果不是就遍历链表插入(插入的是链表尾部)。
264264

265-
![ ](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019-7/put方法.png)
265+
![ ](https://qingcheng-davin.oss-cn-shenzhen.aliyuncs.com/put.png)
266266

267-
说明:上图有两个小问题:
268-
269-
- 直接覆盖之后应该就会 return,不会有后续操作。参考 JDK8 HashMap.java 658 行([issue#608](https://github.com/Snailclimb/JavaGuide/issues/608))。
270-
- 当链表长度大于阈值(默认为 8)并且 HashMap 数组长度超过 64 的时候才会执行链表转红黑树的操作,否则就只是对数组扩容。参考 HashMap 的 `treeifyBin()` 方法([issue#1087](https://github.com/Snailclimb/JavaGuide/issues/1087))。
271267

272268
```java
273269
public V put(K key, V value) {

0 commit comments

Comments
 (0)