一文读懂HashMap和HashTable的区别以及常见面试题(14)


           
       
       ++modCount;        if (++size > threshold)
           resize();
       afterNodeInsertion(evict);        return null;
   

\n

JDK1.8在链表长度超过8时会转换为红黑树 。 转换方法如下:

\n

final void treeifyBin(Node<KV>[
tab int hash) {        int n index; Node<KV> e;        if (tab == null || (n = tab.length) < MIN_TREEIFY_CAPACITY)        //如果节点数变小小于红黑树的节点数阈值时 , 调整空间
           resize();        else if ((e = tab[index = (n - 1) & hash
) != null) {
           TreeNode<KV> hd = null tl = null;            do {            //该方法直接返回一个红黑树结点 。

推荐阅读