In the LinkedHashMap class constructor the first parameter is a maximum number of elements, usually it doubles with achieving to maximum, but only if method removeEldestEntry returns false (by default it always does it). But in this example it is overriden in an anonymous class and returns true if size()>num.
But the third parameter determines the order in which pairs will be stored < Key, Value >. By default (false), they are stored in the insert-order. If the third parameter is true, access-order is used.
All this can be used to organize an LRU-cache, i.e. adding a new element will remove from the cache element with the longest absence of usage (Least Recently Used - LRU).
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати