Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; public class Main { public static <T> List<? extends T> concatSuper(List<? extends T> collection1, List<? extends T> collection2) { if (isEmpty(collection1)) { return collection2; } if (isEmpty(collection2)) { return collection1; } List<T> result = createArrayList(collection1.size() + collection2.size()); result.addAll(collection1); result.addAll(collection2); return result; } public static boolean isEmpty(Map<?, ?> map) { return (map == null) || (map.size() == 0); } public static boolean isEmpty(Collection<?> collection) { return (collection == null) || (collection.size() == 0); } public static <E> ArrayList<E> createArrayList() { return new ArrayList<E>(); } public static <E> ArrayList<E> createArrayList(int initialCapacity) { return new ArrayList<E>(initialCapacity); } public static <E> ArrayList<E> createArrayList(Collection<? extends E> collection) { if (collection == null) { return new ArrayList<E>(); } return new ArrayList<E>(collection); } public static <E> ArrayList<E> createArrayList(Iterable<? extends E> iter) { if (iter instanceof Collection<?>) { return new ArrayList<E>((Collection<? extends E>) iter); } ArrayList<E> list = new ArrayList<E>(); iterableToCollection(iter, list); list.trimToSize(); return list; } public static <T, V extends T> ArrayList<T> createArrayList(V... args) { if (args == null || args.length == 0) { return new ArrayList<T>(); } ArrayList<T> list = new ArrayList<T>(args.length); for (V v : args) { list.add(v); } return list; } private static <E> void iterableToCollection(Iterable<? extends E> iter, Collection<E> list) { if (iter == null) { return; } for (E element : iter) { list.add(element); } } }