removeEldestEntry
removeEldestEntry is a protected hook method in the LinkedHashMap class that allows a class to impose a policy for removing the eldest entry when a new one is inserted. The method signature is protected boolean removeEldestEntry(Map.Entry<K,V> eldest). By default, it returns false, so no removal occurs. After put or putAll inserts a new entry, LinkedHashMap calls this method and, if the result is true, removes the eldest entry from the map.
Usage and pattern: removeEldestEntry is commonly used to implement bounded caches. You subclass LinkedHashMap and override
class LruCache<K,V> extends LinkedHashMap<K,V> {
public LruCache(int maxEntries) {
super(maxEntries, 0.75f, true);
}
protected boolean removeEldestEntry(Map.Entry<K,V> eldest) {
}
}
Notes: removeEldestEntry is a subclassing hook, not part of the Map interface, and is not applicable