0

By my understanding about internal working of LinkedHashMap, it stores values in a array of Node. where Node contains fields :

class Node<K,V> {
 int hash;
 K key;
 V value;
 Node<K,V> next;
 Node<K,V> prev;

}

Correct me if I'm wrong, LinkedHashMap stores insertion order and to maintain that order it stores Node which is inserted before the current node at 'prev' and node which inserted after current node at 'next'. Then where it stores the new node which having same index value like current node ?

  • In case of same bucket location, the new Entry will be stored as next node of the existing Entry. Considering there's only one entry at that location then that Entry's next would be your newly added Entry – implosivesilence May 20 '21 at 14:25

1 Answers1

0

If I understood correctly, it just replaces the old value with the new value if the key is the same