impletement LRU class which extends LinkedHashMap and override removeEldestEntry like this:
class LRULinkedHashMap<K,V> extends LinkedHashMap<K,V>{
private int capacity;
LRULinkedHashMap(int capacity){
super(16,0.75f,true);
this.capacity=capacity;
}
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest){
return size() > capacity;
}
}
For further info please check this : Link Here!