SirNickParks
SirNickParks

Reputation: 107

Java hashmap max size of 5770?

I was testing some file/profile transferring things today. I used a HashMap to store a players name and the value of there profile. However I noticed my hashmap only goes up to 5770 in size. Why is this and how can I fix it?

HashMap<String, String> temp = new HashMap<String, String>();
for(String s : dataFile.getConfigurationSection("users").getKeys(false)) {
        temp.put(s, dataFile.getString("users." + s + ".group"));
}

That's what i'm using to grab the player and their "group".

Upvotes: 10

Views: 39261

Answers (2)

DanielM
DanielM

Reputation: 4033

HashMap is not limited, your problem is probably you have repeating keys..

I would check if the key is contained already before putting it in the map:

if(temp.containsKey(s)){
 System.out.println("Erasing key "+s+" val "+temp.get(s));
}
temp.put(s, dataFile.getString("users." + s + ".group"));

Upvotes: 16

Ankur Singhal
Ankur Singhal

Reputation: 26067

HashMap is not limited, provided to have a load factor is increased.

In Sun's JVM, HashMap uses an array which is a power of 2. The largest power of two allowed for an array size is 2^30. And the largest number of elements you can have before the HashMap will try to double its size to 2^31 (which it cannot do) is (2^30 * loadFactor) or about 700 million for the default load factor.

Upvotes: 17

Related Questions