Iterate LinkedHashMap in Java

In this tutorial, we will learn how to Iterate LinkedHashMap in Java.

LinkedHashMap in Java is Hash table and Linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. It maintains a linked list of the entries in the map, in the order in which they were inserted. This allows insertion-order iteration over the map. That is, when iterating through a collection-view of a LinkedHashMap, the elements will be returned in the order in which they were inserted.

There are many ways to iterate LinkedHashMap in Java. We can iterate LinkedHashMap using Iterator or for loop or while loop etc. If we want to iterate using Iterator, then we need to get Iterator by calling the method iterator() on LinkedHashMap. Let’s see this with an example.




Related posts

Leave a Comment