Java Collection Add addAll(final TCollection target, final Iterable source)

Here you can find the source of addAll(final TCollection target, final Iterable source)

Description

Adds all the elements of the given source to the given target collection.

License

Open Source License

Parameter

Parameter Description
TElement The type of the elements of the given collection.
TCollection The type of the given collection.
target The given collection to copy values to.
source The given source of values.

Return

The given target collection (for chaining purposes).

Declaration

public static <TElement, TCollection extends Collection<TElement>> TCollection addAll(final TCollection target,
        final Iterable<? extends TElement> source) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

public class Main {
    /**/*from  w  w w.j a v  a2s  .co m*/
     * Adds all the elements of the given source to the given target collection.
     *
     * @param <TElement> The type of the elements of the given collection.
     * @param <TCollection> The type of the given collection.
     * @param target The given collection to copy values to.
     * @param source The given source of values.
     * @return The given target collection (for chaining purposes).
     * @note If either the source or the target are not effective, no
     * modifications are made.
     */
    public static <TElement, TCollection extends Collection<TElement>> TCollection addAll(final TCollection target,
            final Iterable<? extends TElement> source) {
        if (target != null && source != null) {
            for (TElement element : source) {
                target.add(element);
            }
        }
        return target;
    }
}

Related

  1. addAll(final Collection collection, final T... elements)
  2. addAll(final Collection collection, final T... objects)
  3. addAll(final Collection collection, final T... objects)
  4. addAll(final Collection collection, final T[] items)
  5. addAll(final T[] source, final Collection destination)
  6. addAll(Iterable iterable, Collection collection)
  7. addAll(Iterable iterable, Collection collection)
  8. addAll(S collection, T... values)
  9. addAll(T coll, Collection other)