Java does nothing. The JDK implementation of that method is:
return false;
It is there as an extension point for people who want to customize the behaviour of the map in their own sub-classes.
If you change it to return true, the runtime is still O(1). The list is maintained in insertion order. All it does is remove the head, which does not require any iteration. Just do the standard HashMap remove and then reassign two pointers.
// Remove eldest entry if instructed, else grow capacity if appropriate
Entry<K,V> eldest = header.after;
if (removeEldestEntry(eldest)) {
//This is the standard HashMap remove, which then finishes by
//calling Map.Entry#remove() on the removed entry.
removeEntryForKey(eldest.key);
}
private static class Entry<K,V> extends HashMap.Entry<K,V> {
// These fields comprise the doubly linked list used for iteration.
Entry<K,V> before, after;
/**
* Removes this entry from the linked list.
*/
private void remove() {
before.after = after;
after.before = before;
}