Skip to content

Instantly share code, notes, and snippets.

@frhan
Created May 24, 2020 14:04
Show Gist options
  • Save frhan/397977ec5e62cc048345c97734424828 to your computer and use it in GitHub Desktop.
Save frhan/397977ec5e62cc048345c97734424828 to your computer and use it in GitHub Desktop.
import java.util.LinkedHashMap;
import java.util.Map;
public class MaxSizeHashMap<K, V> extends LinkedHashMap<K, V> {
private final int maxSize;
public MaxSizeHashMap(int maxSize) {
super(maxSize);
this.maxSize = maxSize;
}
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > maxSize;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment