Wednesday, May 18, 2011

HashSet class in java


  • Set interface implemented using a hash table
  • doesn't guarantee to iterate the elements in any specific order
  • constant time access to elements assuming good hash

HashSet class Constructors

HashSet is implemented with an underlying HashMap. In addition to implemented the Set interface methods, HashSet has the following constructors.
Result Constructor Description
hset = new HashSet() Creates a new HashSet with default initial capacity 16 and load factor 0.75.
hset = new HashSet(initialCapacity) Creates a new HashSet with the specified initial int capacity.
hset = new HashSet(initialCapacity, loadFactor) Creates a new HashSet with the specified capacity which will not exceed a specified (float) load factor.
hset = new HashSet(coll) Creates a new HashSet with elements from the Collection coll

No comments:

Post a Comment