HashSet class


see Collection interfacefor descriptions and examples of all of HashSet's methods



■ This class implements the Set Interface, and extends the AbstractSet class.It is for everyday Set usage.


HashSetis for unordered Sets (with no duplicates allowed) in random or indeterminate order. So you can't control the order here.i.e. The snippet below will print1 3 2or3 2 1, depending on your JVM, not1 2 3which is the order in which the three items were entered.


import java.util.*;


Set hs = new HashSet( );




System.out.println( hs );†††††


HashSetís everyday constructors:


HashSet hs = new HashSet( );††††††††††††††††††††††††† creates an empty set

HashSet hs = new HashSet(Collection);†††††††† creates a set from any Collection