jdk8 hashmap 链表resize 源码分析
Posted javaddd
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jdk8 hashmap 链表resize 源码分析相关的知识,希望对你有一定的参考价值。
重点看这部分代码
for (int j = 0; j < oldCap; ++j) { Node<K,V> e; if ((e = oldTab[j]) != null) { oldTab[j] = null; if (e.next == null) newTab[e.hash & (newCap - 1)] = e; else if (e instanceof TreeNode) ((TreeNode<K,V>)e).split(this, newTab, j, oldCap); else { // preserve order Node<K,V> loHead = null, loTail = null; Node<K,V> hiHead = null, hiTail = null; Node<K,V> next; do { next = e.next; if ((e.hash & oldCap) == 0) { if (loTail == null) loHead = e; else loTail.next = e; loTail = e; } else { if (hiTail == null) hiHead = e; else hiTail.next = e; hiTail = e; } } while ((e = next) != null); if (loTail != null) { loTail.next = null; newTab[j] = loHead; } if (hiTail != null) { hiTail.next = null; newTab[j + oldCap] = hiHead; } } } }
执行图示
以上是关于jdk8 hashmap 链表resize 源码分析的主要内容,如果未能解决你的问题,请参考以下文章