HashMap中put方法的流程图
2021-12-06 15:07:43 9 举报
登录查看完整内容
JDK8中HaahMap的put流程图
作者其他创作
大纲/内容
++size>threshold
计算机索引、逻辑判断
是
key是否存在
table[i]是否为TreeNode
否
开始遍历链表
直接插入
扩容
resize();初始化
链表长度是否大于8
table[i] == null
table==null Or length==0
链表插入,如果key存在,直接覆盖value
链表
红黑树
红黑树直接插入键值对
根据key计算得到的hash值进行hash&(capacity-1)得到插入数组索引i
直接覆盖value
转换红黑树,插入键值对
resize();扩容
return null
![HashMap中put方法的流程图](https://www.processon.com/chart_image/template/thumb/61adb4101e085318d3f598f5.png?tid=61adb4101e085318d3f598f2)
收藏
![Java集合类](https://www.processon.com/chart_image/template/thumb/6168f6a5f346fb06a9eefc8c.png?tid=6168f6a5f346fb06a9eefc8a)
收藏
0 条评论
回复 删除
下一页