Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Set; public class Main { public static <T> Set<T> toSet(Set<T> set, T... arr) { if (set == null) { set = new HashSet<T>(); } return (Set<T>) copy(set, arr); } public static <T> Collection<T> copy(Collection<T> col, T... arr) { if (col == null) { col = new ArrayList<T>(arr.length); } for (T t : arr) { col.add(t); } return col; } }