Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

Load factor in collections

HashMap hashMapName = new HashMap(5, .9);
//The 5 sets the initial element capcaity.
//The .9 is the load factor.  
//  The default load factor is .75.

I was reading above code. I have not understood what it mean by loead factor. please advise
Any ideas, sample code, links, resources highly appreciated. thanks in advance
Avatar of for_yan
for_yan
Flag of United States of America image


The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased.

http://www.coderanch.com/t/521319/java/java/HashMap-load-factor



http://stackoverflow.com/questions/434989/hashmap-intialization-parameters-load-initialcapacity

As a general rule, the default load factor (.75) offers a good tradeoff between time and space costs. Higher values decrease the space overhead but increase the lookup cost (reflected in most of the operations of the HashMap class, including get and put). The expected number of entries in the map and its load factor should be taken into account when setting its initial capacity, so as to minimize the number of rehash operations. If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur.
It means that if you initially specified 100 elements in HashTable, when you fill in this
HashTable to 75 (assuming loadfactor is 0.75) then virtual machine will automaticalluy incerease its capacity,
so that certain share of it is emapty and ready to be filled in when you add next element
Avatar of Mick Barry
Avatar of gudii9

ASKER

>>. Higher values decrease the space overhead but increase the lookup cost (reflected in most of the operations of the HashMap class, including get and put). The expected number of entries in the map and its load factor should be taken into account when setting its initial capacity, so as to minimize the number of rehash operations

>>virtual machine will automaticalluy incerease its capacity,

If i say .95 does not it increase as much as when i say say .75
can you please elaborate on this
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial