From 1a7249d49363e78bb1d647578f3de297a34788da Mon Sep 17 00:00:00 2001 From: Davin-Lee <45418134+Davin-Lee@users.noreply.github.com> Date: Thu, 13 Jul 2023 22:52:08 +0800 Subject: [PATCH] Update hashmap-source-code.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改动行数265 将put流程图更新,地址是用的阿里云oss --- docs/java/collection/hashmap-source-code.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/java/collection/hashmap-source-code.md b/docs/java/collection/hashmap-source-code.md index 5e82eaa736c..5748458155c 100644 --- a/docs/java/collection/hashmap-source-code.md +++ b/docs/java/collection/hashmap-source-code.md @@ -262,12 +262,8 @@ HashMap 只提供了 put 用于添加元素,putVal 方法只是给 put 方法 1. 如果定位到的数组位置没有元素 就直接插入。 2. 如果定位到的数组位置有元素就和要插入的 key 比较,如果 key 相同就直接覆盖,如果 key 不相同,就判断 p 是否是一个树节点,如果是就调用`e = ((TreeNode)p).putTreeVal(this, tab, hash, key, value)`将元素添加进入。如果不是就遍历链表插入(插入的是链表尾部)。 -![ ](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019-7/put方法.png) +![ ](https://qingcheng-davin.oss-cn-shenzhen.aliyuncs.com/put.png) -说明:上图有两个小问题: - -- 直接覆盖之后应该就会 return,不会有后续操作。参考 JDK8 HashMap.java 658 行([issue#608](https://github.com/Snailclimb/JavaGuide/issues/608))。 -- 当链表长度大于阈值(默认为 8)并且 HashMap 数组长度超过 64 的时候才会执行链表转红黑树的操作,否则就只是对数组扩容。参考 HashMap 的 `treeifyBin()` 方法([issue#1087](https://github.com/Snailclimb/JavaGuide/issues/1087))。 ```java public V put(K key, V value) {