-
Notifications
You must be signed in to change notification settings - Fork 45.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HashMap源码分析中put的方法的流程图的疑问 #608
Comments
直接覆盖之后应该就会 return,不会有后续操作。这个图确实有问题。 |
确实,源码实现是直接返回被覆盖的值的。 |
如果是putIfAbsent的话才不会被覆盖掉,返回原来的值,主要看那个onlyIfAbsent |
PutIfAbsent Or OnlyIfabsent serve what purpose |
扩容之后返回null,直接覆盖的话会返回原来的value值。 |
长度大于8后转换成红黑树那里有问题吧?后续不会执行红黑树插入逻辑,只是长度大于8后会进行树化,节点已经在上一步插入至链表了。 参考 JDK8 HashMap.java 642 行 -> 执行尾插至链表逻辑 |
有一个疑问,是否可以这样理解,除了直接追加数组元素 但是 if (tab == null || (n = tab.length) < MIN_TREEIFY_CAPACITY) resize(); 难道是仅仅只会在整个数组为空,或者长度小于 64 是进行扩容?
|
图中若key存在,直接覆盖其节点值,这时不应该将size加1吧?按照源码分析应该直接返回被覆盖之前的值吧?
The text was updated successfully, but these errors were encountered: