public class LRUCache<K, V> extends LinkedHashMap<K, V> {
public int size;
public LRUCache(int initialCapacity, float loadFactor, boolean accessOrder) {
super(initialCapacity, loadFactor, accessOrder);
this.size = initialCapacity;
}
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > size;
}
public static void main(String[] args) {
LRUCache<String, String> lruCache = new LRUCache<String, String>(5, 0.75f, true);
lruCache.put("a", "a");
lruCache.put("b", "b");
lruCache.put("c", "c");
lruCache.put("d", "d");
lruCache.put("e", "e");
System.out.println(lruCache);
System.out.println("-----------");
lruCache.get("b");
System.out.println(lruCache);
System.out.println("-----------");
lruCache.put("f", "f");
lruCache.put("g", "g");
System.out.println(lruCache);
}
}