• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding Collection

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two questions related to Collection API :

1.
The java.util.HashSet contains a constructor which
takes loadfactor as the second argument :
public HashSet(int initialCapacity, float loadFactor)
I want to know what the loadFactor does.
(It is the ratio of the number of the elements to the current capacity, that is what i have to read )
Can someone explain it to me ?

2.
Secondly do i need to remember all the methods in Collection API
as per their return types and the arguments .If yes then, is
there some easy way to do so ?
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Angela,
1.
Here's what the Java Class Libraries, 2nd Edition, Vol. 1 Supplement says about the capacity and load factor


The capcity of the HashSet affects the performance of all the methods. The larger the capacity, typically, the better the performance. However, a larger capacity takes up more memory. Also, a larger capacity will slow the time it takes to use an itrator to iterate over the set....
The load factor controls when the capacity should be increased. In particular, the HashSet doubles the capacity when
size() = load_factor > capacity.
Roughly speaking a larger load factor will make more efficient use of memory at the expense of performance; a smaller load factor improves performance by using more memory.


The default capacity is 101 if no collection is given. Otherwise, it will be 2 * collection.size(). The default load factor is 0.75f. Which, I guess, means more memory will automatically given to the set once it reaches 75% of it's original capacity.
2. You need to be familiar with the methods that are common to all collections and how the collections work i.e. if they can have duplicate elements, if the elements are ordered or unordered, which collections have keys, etc.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited August 03, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic