Home >Java >javaTutorial >How to add elements to LinkedHashMap in java
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!