Here is a Java Program to Demonstrate HashSet.
Output of Above Java Program
[D, E, F, A, B, C]
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]