Here you can find the source of addAll(Collection
Parameter | Description |
---|---|
pCollection | the collection |
pIterator | the elements to add |
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. |
public static <E> void addAll(Collection<E> pCollection, Iterator<? extends E> pIterator)
//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()); } } }