首頁  >  文章  >  Java  >  java中LinkedHashMap怎麼加入元素

java中LinkedHashMap怎麼加入元素

王林
王林轉載
2023-05-13 12:52:061407瀏覽

1、說明

addEntry先把資料加到HashMap中的結構中(數組單向鍊錶),然後呼叫addBefore,其實就是挪動自己和Header的Before與After成員變數指標把自己加到雙向鍊錶的尾巴上。

2、實例

 void addEntry(int hash, K key, V value, int bucketIndex) {
     createEntry(hash, key, value, bucketIndex);
 
     // Remove eldest entry if instructed, else grow capacity if appropriate
     Entry<K,V> eldest = header.after;
     if (removeEldestEntry(eldest)) {
         removeEntryForKey(eldest.key);
     } else {
         if (size >= threshold)
             resize(2 * table.length);
    }
 }

以上是java中LinkedHashMap怎麼加入元素的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除