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".
it's two's complement binary integer is 10000000-00000000-00000000-00000000. It says the maximum size to which hash-map can expand is 1,073,741,824 = 2^30.
Initial Capacity of HashMap The initial capacity of the HashMap is the number of buckets in the hash table. It creates when we create the object of HashMap class. The initial capacity of the HashMap is 24, i.e., 16. The capacity of the HashMap is doubled each time it reaches the threshold.
For hashmap, with the increase of the number of entries, the hashmap's space will increase linearly. So space complexity is O(n) .
HashMap size() Method in Java util. HashMap. size() method of HashMap class is used to get the size of the map which refers to the number of the key-value pair or mappings in the Map. Parameters: The method does not take any parameters.
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.
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With