Set: toArray(String[] a) : Set « java.util « Java by API






Set: toArray(String[] a)

 
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    // A string array with duplicate values
    String[] data = { "A", "C", "B", "D", "A", "B", "E", "D", "B", "C" };
    System.out.println("Original array         : " + Arrays.toString(data));

    List<String> list = Arrays.asList(data);
    Set<String> set = new HashSet<String>(list);

    System.out.print("Remove duplicate result: ");

    String[] result = new String[set.size()];
    set.toArray(result);
    for (String s : result) {
      System.out.print(s + ", ");
    }
  }
}

   
  








Related examples in the same category

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