[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Load factor in collections

Posted on 2011-04-21
6
Medium Priority
?
314 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
0
Comment
Question by:gudii9
  • 3
  • 2
6 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35442437

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.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35442460
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
0
 
LVL 92

Expert Comment

by:objects
ID: 35444613
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Author Comment

by:gudii9
ID: 35708303
>>. 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
0
 
LVL 47

Accepted Solution

by:
for_yan earned 1000 total points
ID: 35708447
if you say .95 and you have 95 records present it will allocate space up to 100,
so space 5 entries for now will be held empty
if you say .75 and you have 95 records it will keep space for approximately 95/4
(25 % more) for about 23 more entries
0
 
LVL 92

Assisted Solution

by:objects
objects earned 1000 total points
ID: 35711014
its the ratio between the number of entries and the size of the bucket array.
So a lower load factor will increase the space required
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month20 days, 7 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question