Java tutorial
//package com.java2s; import java.util.*; public class Main { public static <T> HashSet<T> createHashSet() { return new HashSet(); } public static <T, V extends T> HashSet<T> createHashSet(V... args) { if ((args == null) || (args.length == 0)) { return new HashSet(); } HashSet<T> set = new HashSet(args.length); for (V v : args) { set.add(v); } return set; } public static <T> HashSet<T> createHashSet(Iterable<? extends T> c) { HashSet<T> set; if ((c instanceof Collection)) { set = new HashSet((Collection) c); } else { set = new HashSet(); iterableToCollection(c, set); } return set; } private static <T> void iterableToCollection(Iterable<? extends T> c, Collection<T> list) { for (T element : c) { list.add(element); } } }