Let’s dive into a fascinating corner of Java’s Collections Framework: the LinkedHashMap. You might already be familiar with HashMap for its speedy key-value pair storage and LinkedHashSet for maintaining insertion order in a set. Well, LinkedHashMap is the best of both worlds, offering the familiar map interface with the added benefit of predictable iteration order.
Let’s break down what makes LinkedHashMap so special and when you should consider using it.
What is LinkedHashMap?
In simple terms, LinkedHashMap is a hash table and a linked list implementation of the Map interface. It inherits all the goodness from HashMap (fast lookups, insertions, and deletions) but adds an internal doubly-linked list that runs through all of its entries. This linked list defines the iteration order, which can either be:
- Insertion Order:Â The default behavior, where elements are iterated in the order they were first inserted into the map.
- Access Order:Â Elements are iterated in the order they were last accessed (read or written). This is particularly useful for implementing LRU (Least Recently Used) caches.
Like HashMap, LinkedHashMap allows one null key and multiple null values.
Interface Hierarchy

LinkedHashMap implements the following interfaces and extends the following class:
java.io.Serializablejava.util.Mapjava.lang.Cloneable
And it extends java.util.HashMap.