简体   繁体   中英

understanding HashMap<Integer, Object>(3)

This maybe due to my lack of Java experience, but I set this hashmap to allow 3(or 4) entries into it like this:

 Map<Integer, Object> myAwesomeCache = new HashMap<Integer, Object>(3);
 for (int i = 0; i < 222; i++)
 {
      myAwesomeCache.put(i, "dd");
 }

However, my loop which is set to 222 continues to populate it until there are 222 entries in there. Can someone explain to me why this is?

seehttp://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html

The value you are passing is not a maximum, it's just the starting size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM