-
Notifications
You must be signed in to change notification settings - Fork 46k
Open
Labels
discussdiscuss a problemdiscuss a problemdoc-bugContent errorContent errorenhancementNew feature or request or suggestionNew feature or request or suggestionperfectImprove knowledge points or descriptionsImprove knowledge points or descriptions
Description
作者在 JDK1.8之后 这一小节的开头中写道:
JDK1.8之后再解决哈希冲突问题时有了较大的变化,当链表长度大于阈值(默认为8)时,将链表转化为红黑树,以减少搜索时间
这段话加粗部分的描述是不准确的,当链表长度大于阈值时,会尝试调用树化方法treeifyBin,但这不意味着会将链表转为树:
当我们查看树化方法treeifyBin(JDK1.8 HashMap源码)时,应注意到这么一行代码(757行):
我们发现,当哈希表的length小于MIN_TREEIFY_CAPACITY (默认为64)时,并不会真正树化,而只是执行resize(),也就是扩容的操作,这一点在对树化方法treeifyBin以及MIN_TREEIFY_CAPACITY
的注释中都有提到:
如果我的看法有什么错漏之处,恳请大家补充指正
debugjoker, WillfordZhan, altya, Rorke76753, shahainloong and 2 more
Metadata
Metadata
Assignees
Labels
discussdiscuss a problemdiscuss a problemdoc-bugContent errorContent errorenhancementNew feature or request or suggestionNew feature or request or suggestionperfectImprove knowledge points or descriptionsImprove knowledge points or descriptions



