Linked HashMap in Java

LinkedHashMap extends the HashMap class in Java. We will discuss Linked Hashmap in Java, It stores the element in the LinkedList and maintains the Insertion order.

 

That’s why, when iterating through a collection-view of a LinkedHashMap, the elements will be returned in the order in which they were inserted. Also, if one inserts the key again into the LinkedHashMap the original orders are retained. This allows insertion-order iteration over the map. That is, when iterating a LinkedHashMap, the elements will be returned in the order in which they were inserted. You can also create a LinkedHashMap that returns its elements in the order in which they were last accessed.

 

Example of Linked HashMap in Java

Let’s see the example of LinkedHashMap. In the below example we are implementing the LinkedHashMap and performing the different actions on the LinkedHashMap.

Output:

LinkedHashMap before modification{1=Anshul, 12=Mirilla, 10=Terrna, 15=Eden, 19=Matt, 23=Rubi, 13=Ankit, 4=Rodney}
Is Employee ID 15 exists: true
Is Employee name Terrna Exists: true
Total number of employees: 8
Removing Employee with ID 12: Mirilla
Removing Employee with ID 33 (which does not exist): null
LinkedHashMap After modification{1=Anshul, 10=Terrna, 15=Eden, 19=Matt, 23=Rubi, 13=Ankit, 4=Rodney}

 

In the above example, we have implemented the LinkedHashMap ‘lmap’ and performed the operations on this LinkedHashMap. You can see, We have implemented the many operations on LinkedHashmap.

This is, how we can implement the LinkedHashMap and perform the operation on it.

 

Selenium Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

0 Comment

Leave a Reply