Java Collection Add addAll(Collection dest, T... elements)

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

Description

Adds element from an array into a collection.

License

Open Source License

Parameter

Parameter Description
dest the destination collection which cannot be <code>null</code> and should be able to accept the input elements.
elements the element to add to <code>dest</code>
T collection type element.

Exception

Parameter Description
UnsupportedOperationException if the <tt>add</tt> operationis not supported by <code>dest</code>.
ClassCastException if the class of any of the elementsprevents it from being added to <code>dest</code>.
NullPointerException if any of the elements is <code>null</code> and <code>dest</code>does not permit <code>null</code> elements
IllegalArgumentException if some property of any of the elementsprevents it from being added to this collection
IllegalStateException if any of the elements cannot be added at thistime due to insertion restrictions.

Return

true if the collection was modified as a result.

Declaration

public static <T> boolean addAll(Collection<T> dest, T... elements) 

Method Source Code

//package com.java2s;
/*//from w ww.  ja  v a 2 s.co  m
* Copyright 2012-2016 Broad Institute, Inc.
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import java.util.*;

public class Main {
    /**
     * Adds element from an array into a collection.
     *
     * In the event of exception being throw due to some element, <code>dest</code> might have been modified by
     * the successful addition of element before that one.
     *
     * @param dest the destination collection which cannot be <code>null</code> and should be able to accept
     *             the input elements.
     * @param elements the element to add to <code>dest</code>
     * @param <T>  collection type element.
     * @throws UnsupportedOperationException if the <tt>add</tt> operation
     *         is not supported by <code>dest</code>.
     * @throws ClassCastException if the class of any of the elements
     *         prevents it from being added to <code>dest</code>.
     * @throws NullPointerException if any of the elements is <code>null</code> and <code>dest</code>
     *         does not permit <code>null</code> elements
     * @throws IllegalArgumentException if some property of any of the elements
     *         prevents it from being added to this collection
     * @throws IllegalStateException if any of the elements cannot be added at this
     *         time due to insertion restrictions.
     * @return <code>true</code> if the collection was modified as a result.
     */
    public static <T> boolean addAll(Collection<T> dest, T... elements) {
        boolean result = false;
        for (final T e : elements) {
            result = dest.add(e) | result;
        }
        return result;
    }
}

Related

  1. addAll(Collection collection, T[] array)
  2. addAll(Collection collection, T[] array)
  3. addAll(Collection collection, T[] items)
  4. addAll(Collection dest, Collection src, Class type)
  5. addAll(Collection dest, Collection orig)
  6. addAll(Collection intoCollection, Collection fromCollection)
  7. addAll(Collection left, Collection right)
  8. addAll(Collection t1, Iterable t2)
  9. addAll(Collection target, Collection source)