Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class Main { public static <T> List<T> asList(T e0, T e1) { ArrayList<T> result = new ArrayList<>(2); result.add(e0); result.add(e1); return result; } public static <T> List<T> asList(T e0, T e1, T e2) { ArrayList<T> result = new ArrayList<>(3); result.add(e0); result.add(e1); result.add(e2); return result; } @SafeVarargs public static <T> List<T> asList(T... elements) { ArrayList<T> result = new ArrayList<>(elements.length); Collections.addAll(result, elements); return result; } public static <T> boolean addAll(Collection<T> collection, Collection<? extends T> toAdd) { int size = toAdd.size(); boolean result = false; if (size > 0) { if (size < 10) for (T element : toAdd) result |= collection.add(element); else result = collection.addAll(toAdd); } return result; } @SafeVarargs public static <T> boolean addAll(Collection<T> collection, T... toAdd) { int size = toAdd.length; boolean result = false; if (size > 0) { for (T element : toAdd) result |= collection.add(element); } return result; } }