intermediate~3h
LinkedHashMap and Building an LRU Cache
How LinkedHashMap layers predictable ordering on top of HashMap's bucket structure, and how to turn that into a complete, working least-recently-used cache with a single constructor flag and one overridden method.
Learning objectives
- Explain how LinkedHashMap maintains both HashMap's bucket structure and a separate doubly-linked list for ordering
- Distinguish insertion-order mode from access-order mode and know which constructor flag controls it
- Implement a complete, correct LRU cache by extending LinkedHashMap and overriding removeEldestEntry
- Explain why this is one of the most common system-design and coding-interview exercises involving collections
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Core Java Mastery library.
LinkedHashMap and Building an LRU Cache