Convert array to Set in Java
Description
The following code shows how to convert array to Set.
Example
//from w w w . j ava 2 s . c o m
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
public class Main {
public static void main(String args[]) throws Exception {
String elements[] = { "A", "C", "D", "G", "F" };
Set set = new TreeSet(Arrays.asList(elements));
System.out.println(set);
}
}
The code above generates the following result.