This is a question that comes up a lot in job interviews. The idea is to define a data structure instead of using Java\'s built in LinkedHashMap.
An LRU cache delete
public class LeastRecentlyUsed {
public static Map leastRecentlyUsedCache(final int maxSize) {
return new LinkedHashMap(maxSize , 0.7f, true) {
private static final long serialVersionUID = -3588047435434569014L;
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > maxSize;
}
};
}
public static void main(String[] args) {
Map