通过继承LinkedHashMap实现LRU:
import java.util.LinkedHashMap; import java.util.Map; public class LRUCache<K, V> extends LinkedHashMap<K, V> { private int size; public LRUCache(int size) { super((int) Math.ceil(size / 0.75) + 1, 0.75f, true); this.size = size; } protected boolean removeEldestEntry(Map<K, V> eldest) { return size() > size; } }
通过双向链表+map可以实现LRU
原文:https://www.cnblogs.com/use-D/p/12622681.html