Java examples for java.util:Collection Convert
Convert Collection to HashSet
import java.util.Collection; import java.util.HashSet; import java.util.Set; public class Main { @SafeVarargs// w ww.j a v a 2 s.com public static <T> Set<T> hashSet(T... values) { Set<T> set = new HashSet<>(); for (T value : values) { set.add(value); } return set; } public static <T> Set<T> hashSet(Collection<T> values) { Set<T> set = new HashSet<>(); for (T value : values) { set.add(value); } return set; } }