I want to limit the maximum size of a HashMap
to take metrics on a variety of hashing algorithms that I\'m implementing. I looked at the loadfactor in one of
You could create a new class like this to limit the size of a HashMap:
public class MaxSizeHashMap extends LinkedHashMap {
private final int maxSize;
public MaxSizeHashMap(int maxSize) {
this.maxSize = maxSize;
}
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > maxSize;
}
}