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