Java Collection Add addAll(final Collection thingsToBeAddedTo, final Collection thingsToAdd)

Here you can find the source of addAll(final Collection thingsToBeAddedTo, final Collection thingsToAdd)

Description

Adds thingsToAdd to thingsToBeAddedTo.

License

Apache License

Parameter

Parameter Description
thingsToBeAddedTo , which must be non-null.

Exception

Parameter Description
IllegalArgumentException if thingsToBeAddedTo is null.

Declaration

public static <E> void addAll(final Collection<? super E> thingsToBeAddedTo,
        final Collection<? extends E> thingsToAdd) 

Method Source Code

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

import java.util.Collection;

import java.util.Map;

public class Main {
    /**/*from  w ww .  j  a v a  2s.co  m*/
     * Adds thingsToAdd to thingsToBeAddedTo.
     * 
     * @param thingsToBeAddedTo
     *            , which must be non-null.
     * @throws IllegalArgumentException
     *             if thingsToBeAddedTo is null.
     * 
     */
    public static <E> void addAll(final Collection<? super E> thingsToBeAddedTo,
            final Collection<? extends E> thingsToAdd) {
        if (thingsToBeAddedTo == null) {
            throw new IllegalArgumentException("There's no thingsToBeAddedTo!");
        }

        if (!isEmpty(thingsToAdd)) {
            thingsToBeAddedTo.addAll(thingsToAdd);
        }
    }

    public static boolean isEmpty(Iterable<?> i) {
        if (i instanceof Collection)
            return ((Collection<?>) i).isEmpty();
        return i == null || !i.iterator().hasNext();
    }

    public static boolean isEmpty(Map<?, ?> p_oCol) {
        return p_oCol == null || p_oCol.isEmpty();
    }
}

Related

  1. addAll(Collection target, Iterable source)
  2. addAll(Collection target, S[] source)
  3. addAll(final Collection coll, final Object[] array)
  4. addAll(final Collection newItems, final Collection existingItems)
  5. addAll(final Collection c, final E... array)
  6. addAll(final Collection coll, final T... objs)
  7. addAll(final Collection collection, final T... elements)
  8. addAll(final Collection collection, final T... objects)
  9. addAll(final Collection collection, final T... objects)