+ 1
Hashmap with maximum length?
I'm using a hashmap that never has to hold more than twelve elements. Is it possible to bound the size of the hashmap to prevent it from getting bigger than necessary?
1 Answer
0
You may do it with a conditional:
for example, having :
Hashmap<String, Integer> h = new Hashmap<String, Integer>();
if you want your hashmap to have only 12 elements, you can do this:
if (h.size()<12){h.put("Hank",999);}
else {System.out.println("Hash limit reached");}