Ok so i am new to these HashMaps but have some idea about LinkedLists and HashMaps. It would be great if you could give me some simple explanation regarding LinkedHashMap and a
It is a hybrid of two data structures, a LinkedList
, where insertion order is preserved by adding elements to the end of a list of nodes which have access to their immediate neighbours, and a HashMap
, or a Map
that uses an array of bucket Lists
, where a modulus division remainder of the key's hashcode()
determines the starting bucket to query for the equals()
method of the keys that lie in that bucket's list of contents.
The advantage is that you can walk the existing elements in a HashMap
in order of insertion, due to the LinkedList
nature, and you can quickly jump to the correct bucket in a key lookup (saving a lot of time for a large collection) if you have the key of the element.