Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /** * Join several all provided collections in the first one provided.<br /> * The instance of the target collection is returned to ease use in foreach loops. * @param <T> * the type of the elements contained in the collection. * @param target * the target collection * @param collections * the collections of items to add in the target collection. * @return the first collection, with the other items of the collection added. */ @SafeVarargs public static <T> Collection<T> joinCollections(final Collection<T> target, final Collection<? extends T>... collections) { if (target == null) { throw new IllegalArgumentException("Cannot join collection in null target"); } if (collections.length == 0) { return target; } for (final Collection<? extends T> collection : collections) { target.addAll(collection); } return target; } }