ransfer方法的作用是把原table的Node放到新的table中,使用的是头插法,也就是说,新table中链表的顺序和旧列表中是相反的,在HashMap线程不安全的情况下,这种头插法可能会导致环状节点。
其中的while循环描述了头插法的过程,这个逻辑有点绕,下面举个例子来解析一下这段代码。
假设原有table记录的某个链表,比如table[1]=3,链表为3–>5–>7,那么处理流程为:
/**
* Transfers all entries from current table to newTable.
*/
void transfer(Entry[] newTable, boolean rehash) {
int newCapacity = newTable.length;
for (Entry<K,V> e : ta