Here you can find the source of addToCollection(C collection, E... elements)
Parameter | Description |
---|---|
C | the collection type |
E | the elements type |
collection | the collection to add the elements to. The collection implementation should support <code>null</code> values if such are expected in the second argument. |
elements | a list of elements to add to the specified collection. If any of the elements is <code>null</code> it will be added to the collection. |
@SafeVarargs public static <E, C extends Collection<E>> C addToCollection(C collection, E... elements)
//package com.java2s; //License from project: LGPL import java.util.Collection; public class Main { /**//from w w w .j ava 2 s . co m * Adds elements to a collection. The method modifies the supplied collection by adding the elements from the * variable arguments parameter if any. * * @param <C> * the collection type * @param <E> * the elements type * @param collection * the collection to add the elements to. The collection implementation should support <code>null</code> * values if such are expected in the second argument. * @param elements * a list of elements to add to the specified collection. If any of the elements is <code>null</code> it * will be added to the collection. * @return the same collection instance as the argument with added elements */ @SafeVarargs public static <E, C extends Collection<E>> C addToCollection(C collection, E... elements) { if (collection == null || elements == null || elements.length == 0) { return collection; } for (E e : elements) { collection.add(e); } return collection; } }