Here is a Java Program to Demonstrate HashSet.
Output of Above Java Program
[D, E, F, A, B, C]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import java.util.*; class HashSetDemo { public static void main(String args[]) { // create a hash set HashSet hs = new HashSet(); // add elements to the hash set hs.add( "B" ); hs.add( "A" ); hs.add( "D" ); hs.add( "E" ); hs.add( "C" ); hs.add( "F" ); System.out.println(hs); } } |
Output of Above Java Program
[D, E, F, A, B, C]