LinkedHashMap example in Java

LinkedHashMap is part of the java.util package and it extends the HashMap, so it has all the properties of HashMap. LinkedHashMap maintains the order of insertion of the elements, hence when we iterate a LinkedHashMap we get the elements in the order in which they were inserted.

LinkedHashMap maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted. In this post lets see LinkedHashMap example in Java.

LinkedHashMap example in Java

Output

From the Output you will be able to see that when we iterate the LinkedHashMap, it returns the elements in order exactly as they were inserted.

LinkedHashMap example in Java

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn