Web / Apache Commons Collections Interview questions
How does LRUMap decide which entry to evict?
LRUMap tracks access recency internally using a doubly linked structure layered over its hash table, similar to how LinkedHashMap behaves in access-order mode - every get() or put() moves the touched entry to the "most recently used" end of that internal ordering.
When a put() introduces a brand-new key and the map is already at its configured maximum size, LRUMap looks at the opposite end of that ordering - the entry that has gone the longest without being accessed - and quietly removes it before inserting the new one, rather than throwing an exception or growing unbounded.
This makes recency of access, not just insertion order, the deciding factor: an old entry that keeps getting read stays in the map indefinitely, while a rarely touched entry is the first candidate for eviction even if it was inserted more recently than some untouched neighbors.
More Related questions...