Java Collection Add addAll(Collection coll, T... elems)

Here you can find the source of addAll(Collection coll, T... elems)

Description

Appends an arbitrary number of explicit elements to an existing collection.

License

Apache License

Declaration

public static <T> void addAll(Collection<T> coll, T... elems) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**/*  ww  w. j  a  v  a  2  s . co m*/
     *  Appends an arbitrary number of explicit elements to an existing collection.
     *  Primarily useful when writing testcases.
     */
    public static <T> void addAll(Collection<T> coll, T... elems) {
        for (T elem : elems)
            coll.add(elem);
    }

    /**
     *  Appends the values returned by an iterator to the passed collection.
     */
    public static <T> void addAll(Collection<T> coll, Iterator<T> src) {
        while (src.hasNext())
            coll.add(src.next());
    }

    /**
     *  Appends the contents of an iterable object to the passed collection.
     */
    public static <T> void addAll(Collection<T> coll, Iterable<T> src) {
        addAll(coll, src.iterator());
    }
}

Related

  1. addAll(Collection collection, Iterator iterator)
  2. addAll(Collection pCollection, Iterator pIterator)
  3. addAll(Collection integerCollection, int[] intArray)
  4. addAll(Collection c, T[] a)
  5. addAll(Collection col, T[] arr)
  6. addAll(Collection coll1, Collection coll2)
  7. addAll(Collection collection, Collection toAdd)
  8. addAll(Collection collection, Iterable items)
  9. addAll(Collection collection, T... array)