Java Collection Add addAll(final Collection collection, final T... elements)

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

Description

add All

License

Open Source License

Exception

Parameter Description
IllegalArgumentException if <code>collection == null</code>

Declaration

public static <T> int addAll(final Collection<T> collection, final T... elements)
        throws IllegalArgumentException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Portions created by Sebastian Thomschke are copyright (c) 2005-2016 Sebastian
 * Thomschke./*from   w ww  .  ja va  2  s  .c om*/
 * 
 * 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:
 *     Sebastian Thomschke - initial implementation.
 *******************************************************************************/

import java.util.Collection;

public class Main {
    /**
     * @throws IllegalArgumentException if <code>collection == null</code>
     */
    public static <T> int addAll(final Collection<T> collection, final T... elements)
            throws IllegalArgumentException {
        if (elements == null)
            return 0;

        int count = 0;
        for (final T elem : elements)
            if (collection.add(elem))
                count++;
        return count;
    }
}

Related

  1. addAll(final Collection coll, final Object[] array)
  2. addAll(final Collection newItems, final Collection existingItems)
  3. addAll(final Collection c, final E... array)
  4. addAll(final Collection thingsToBeAddedTo, final Collection thingsToAdd)
  5. addAll(final Collection coll, final T... objs)
  6. addAll(final Collection collection, final T... objects)
  7. addAll(final Collection collection, final T... objects)
  8. addAll(final Collection collection, final T[] items)
  9. addAll(final T[] source, final Collection destination)