Java Collection Add addAll(Collection pCollection, Iterator pIterator)

Here you can find the source of addAll(Collection pCollection, Iterator pIterator)

Description

Adds all elements of the iterator to the collection.

License

Open Source License

Parameter

Parameter Description
pCollection the collection
pIterator the elements to add

Exception

Parameter Description
UnsupportedOperationException if add is not supported bythe given collection.
ClassCastException class of the specified element prevents itfrom being added to this collection.
NullPointerException if the specified element is null and thiscollection does not support null elements.
IllegalArgumentException some aspect of this element preventsit from being added to this collection.

Declaration

public static <E> void addAll(Collection<E> pCollection, Iterator<? extends E> pIterator) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    /**//w w  w .j av  a  2  s  .  com
     * Adds all elements of the iterator to the collection.
     *
     * @param pCollection the collection
     * @param pIterator the elements to add
     *
     * @throws UnsupportedOperationException if {@code add} is not supported by
     *         the given collection.
     * @throws ClassCastException class of the specified element prevents it
     *         from being added to this collection.
     * @throws NullPointerException if the specified element is {@code null} and this
     *         collection does not support {@code null} elements.
     * @throws IllegalArgumentException some aspect of this element prevents
     *         it from being added to this collection.
     */
    public static <E> void addAll(Collection<E> pCollection, Iterator<? extends E> pIterator) {
        while (pIterator.hasNext()) {
            pCollection.add(pIterator.next());
        }
    }
}

Related

  1. addAll(Collection c, T... array)
  2. addAll(Collection coll, Iterable it)
  3. addAll(Collection collection, E... args)
  4. addAll(Collection collection, Iterable iterable)
  5. addAll(Collection collection, Iterator iterator)
  6. addAll(Collection integerCollection, int[] intArray)
  7. addAll(Collection c, T[] a)
  8. addAll(Collection col, T[] arr)
  9. addAll(Collection coll, T... elems)