Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; public class Main { /** * Converts parameters into a set * * @param <T> set element type * @param value element * @return set containing the given elements */ public static <T> Set<T> asSet(T value) { Set<T> set = new HashSet<>(1); set.add(value); return set; } /** * Converts parameters into a set * * @param <T> set element type * @param first element * @param second element * @return set containing the given elements */ public static <T> Set<T> asSet(T first, T second) { Set<T> set = new HashSet<>(2); set.add(first); set.add(second); return set; } /** * Converts parameters into a set * * @param <T> set element type * @param first element * @param second element * @param third element * @return set containing the given elements */ public static <T> Set<T> asSet(T first, T second, T third) { Set<T> set = new HashSet<>(3); set.add(first); set.add(second); set.add(third); return set; } /** * Converts parameters into a set * * @param <T> set element type * @param first element * @param second element * @param third element * @param rest elements * @return set containing the given elements */ @SafeVarargs public static <T> Set<T> asSet(T first, T second, T third, T... rest) { Set<T> set = new HashSet<>(Arrays.asList(rest)); set.add(first); set.add(second); set.add(third); return set; } /** * Returns iterated values as list * * @param iterable iterable to iterate on * @param <T> element type * @return list containing iterated values */ public static <T> List<T> asList(Iterable<T> iterable) { List<T> list = new ArrayList<>(); for (T t : iterable) { list.add(t); } return list; } }