Java tutorial
//package com.java2s; import java.util.*; public class Main { public static <T> Set<T> hashSetFromArray(final T[] objs) { final Set<T> set = new HashSet<T>(); for (final T obj : objs) { set.add(obj); } return set; } /** * Add objects to a collection... mostly used when an object instantiation is in the first paramter. */ public static <T extends Object, C extends Collection<? super T>> C add(final C cxn, final T... objs) { if (objs != null) { for (final T obj : objs) { cxn.add(obj); } } return cxn; } public static <T extends Object, C extends Collection<? super T>> C add(final C cxn, Iterable<T> from) { if (from != null) { for (T obj : from) { cxn.add(obj); } } return cxn; } }