We help IT Professionals succeed at work.

Load factor in collections

gudii9
gudii9 asked
on
Medium Priority
325 Views
Last Modified: 2012-05-11
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
Comment
Watch Question

Awarded 2011
Awarded 2011

Commented:

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.
Awarded 2011
Awarded 2011

Commented:
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
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

Author

Commented:
>>. 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
Awarded 2011
Awarded 2011
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.