HashSet: add(E o) : HashSet « java.util « Java by API






HashSet: add(E o)

 
/**
 *Output: 
[D, A, F, C, B, E]
 */

import java.util.HashSet;

public class MainClass {
  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);
  }
}

           
         
  








Related examples in the same category

1.new HashSet < E > ()
2.new HashSet(Collection c)
3.HashSet: addAll(Collection c)
4.HashSet: clear()
5.HashSet: clone()
6.HashSet: contains(Object o)
7.HashSet: containsAll(Collection c)
8.HashSet: isEmpty()
9.HashSet: iterator()
10.HashSet: removeAll(Collection c)
11.HashSet: size()
12.HashSet: toArray()