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

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

Description

Adds all elements to the Collection .

License

Open Source License

Parameter

Parameter Description
T The type of the Collection s elements.
collection The Collection to add to.
elementsToAdd The elements to add.

Declaration

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

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Karlsruhe Institute of Technology, Germany
 *                    Technical University Darmstadt, Germany
 *                    Chalmers University of Technology, Sweden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:// w  w  w.  j a  va 2 s  .  c o  m
 *    Technical University Darmstadt - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.util.Collection;

public class Main {
    /**
     * Adds all elements to the {@link Collection}. 
     * @param <T> The type of the {@link Collection}s elements.
     * @param collection The {@link Collection} to add to.
     * @param elementsToAdd The elements to add.
     */
    public static <T> void addAll(Collection<T> collection, T... elementsToAdd) {
        if (collection != null && elementsToAdd != null) {
            for (T toAdd : elementsToAdd) {
                collection.add(toAdd);
            }
        }
    }

    /**
     * Adds all elements to the {@link Collection}. 
     * @param <T> The type of the {@link Collection}s elements.
     * @param collection The {@link Collection} to add to.
     * @param elementsToAdd The elements to add.
     */
    public static <T> void addAll(Collection<T> collection, Iterable<T> iterable) {
        if (collection != null && iterable != null) {
            for (T toAdd : iterable) {
                collection.add(toAdd);
            }
        }
    }
}

Related

  1. addAll(Collection coll, T... elems)
  2. addAll(Collection coll1, Collection coll2)
  3. addAll(Collection collection, Collection toAdd)
  4. addAll(Collection collection, Iterable items)
  5. addAll(Collection collection, T... array)
  6. addAll(Collection collection, T... elementsToAdd)
  7. addAll(Collection collection, T... newElements)
  8. addAll(Collection collection, T[] array)
  9. addAll(Collection collection, T[] array)