Add values to HashSet in Java

Description

The following code shows how to add values to HashSet.

Example


//from  www .  j a  va 2s.  c o  m
import java.util.HashSet;

class HashSetDemo {
  public static void main(String args[]) {

    HashSet<String> hs = new HashSet<String>();

    hs.add("B");
    hs.add("A");
    hs.add("D");
    hs.add("E");
    hs.add("C");
    hs.add("F");

    System.out.println(hs);
  }
}




















Home »
  Java Tutorial »
    Java Collection »




Java ArrayList
Java Collection
Java Comparable
Java Comparator
Java HashMap
Java HashSet
Java Iterator
Java LinkedHashMap
Java LinkedHashSet
Java LinkedList
Java List
Java ListIterator
Java Map
Queue
Java Set
Stack
Java TreeMap
TreeSet