0

I know that in HashMap collisions are handled using LinkedList at each index if there is a collision the new node is inserted at the end of LinkedList but in the case of LinkedHashMap we use a doubly-linked list but to maintain order here the next and prev references are already occupied now how collisions are handled?

  • 3
    Does the doumentation not answer this? Why not just read [the source code](https://developer.classpath.org/doc/java/util/LinkedHashMap-source.html)? – Caius Jard Jun 22 '21 at 14:54
  • Also, if the DLL is used to track insertion order (so that the map entries can be enumerated back in the same order they were inserted), what difference does a collision make? Where the item ends up being inserted/tracked by the map is of little consequence to the device that, separately to the map, tracks the order of insertion of items – Caius Jard Jun 22 '21 at 15:04

1 Answers1

0

LinkedHashMap is primarily concerned with establishing a linked list to manage the bucket access of the map. But since LinkedHashMap subclasses HashMap which subclasses AbstractMap, those ancestral classes are still used to handle multiple values per bucket (i.e. collisions).

WJS
  • 36,363
  • 4
  • 24
  • 39