Java examples for Collection Framework:Set
union To Hash Set
import java.util.*; public class Main{ public static void main(String[] argv){ Collection collections = java.util.Arrays.asList("asdf","java2s.com"); System.out.println(unionToHashSet(collections)); }// w w w. java2 s .c o m public static <T> HashSet<T> unionToHashSet( final Collection<T>... collections) { final HashSet<T> res = new HashSet<T>(); for (final Collection<T> set : collections) { res.addAll(set); } return res; } public static <T> HashSet<T> unionToHashSet( final Collection<T> collection, final T... items) { final HashSet<T> result = new HashSet<T>(); result.addAll(collection); Collections.addAll(result, items); return result; } }