Home  >  Article  >  Java  >  How to add elements to LinkedHashMap in java

How to add elements to LinkedHashMap in java

王林
王林forward
2023-05-13 12:52:061449browse

1. Description

addEntry first adds the data to the structure in the HashMap (array one-way linked list), and then calls addBefore, which actually moves the Before and After of itself and the Header. The member variable pointer adds itself to the tail of the doubly linked list.

2. Example

 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);
    }
 }

The above is the detailed content of How to add elements to LinkedHashMap in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete