Created
May 24, 2020 14:04
-
-
Save frhan/397977ec5e62cc048345c97734424828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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