Java Collection Add addAll(Collection collection, T... newElements)

Here you can find the source of addAll(Collection collection, T... newElements)

Description

Add the contents of an array to a collection and return the collection.

License

Apache License

Parameter

Parameter Description
collection the collection to which things are to be added.
newElements the new elements to add to the collection.

Return

the collection after the elements have been added.

Declaration


public static <T> Collection<T> addAll(Collection<T> collection,
        T... newElements) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**/*  ww  w . j  a va2s.  co m*/
     * Add the contents of an array to a collection and return the collection.
     * <p/>Returning the collection facilitates certain constructs including:
     * <blockquote>
     * <tt>doit( ObtuseUtil.addAll( new LinkedList&lt;String>(), new String[] { "hello", "there", "world" } );</tt>
     * </blockquote>
     *
     * @param collection  the collection to which things are to be added.
     * @param newElements the new elements to add to the collection.
     * @return the collection after the elements have been added.
     */

    public static <T> Collection<T> addAll(Collection<T> collection,
            T... newElements) {

        Collections.addAll(collection, newElements);
        return collection;

    }
}

Related

  1. addAll(Collection collection, Collection toAdd)
  2. addAll(Collection collection, Iterable items)
  3. addAll(Collection collection, T... array)
  4. addAll(Collection collection, T... elementsToAdd)
  5. addAll(Collection collection, T... elementsToAdd)
  6. addAll(Collection collection, T[] array)
  7. addAll(Collection collection, T[] array)
  8. addAll(Collection collection, T[] items)
  9. addAll(Collection dest, Collection src, Class type)