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

How to add elements to LinkedHashMap in java

王林
Release: 2023-05-13 12:52:06
forward
1479 people have browsed it

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);
    }
 }
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template