Last active
January 25, 2019 16:11
-
-
Save deque-blog/7bf691aaba1402517f41b963bfc42e99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LRUCache<K, V> extends LinkedHashMap<K, V> { | |
private final int capacity; | |
public LRUCache(int capacity) { | |
super(capacity, 0.75f, true); | |
this.capacity = capacity; | |
} | |
@Override | |
protected boolean removeEldestEntry(Map.Entry<K, V> oldest) { | |
return size() > capacity; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment