Set: add(String e) : Set « java.util « Java by API






Set: add(String e)

 

import java.util.HashSet;
import java.util.Set;

public class Main {

  public static void main(String[] a) {
    Set<String> set = new HashSet<String>();
    set.add("Hello");
    if (set.add("Hello")) {
      System.out.println("addition successful");
    } else {
      System.out.println("addition failed");
    }
  }
}

   
  








Related examples in the same category

1.Set: addAll(Collection c)
2.Set: clear()
3.Set: clone()
4.Set: contains(Object o)
5.Set: containsAll(Collection c)
6.Set: equals(Object o)
7.Set: isEmpty()
8.Set: iterator()
9.Set: remove(Object o)
10.Set: removeAll(Collection c)
11.Set: retainAll(Collection c)
12.Set: size()
13.Set: toArray()
14.Set: toArray(String[] a)