Here you can find the source of addAll(Iterator
Iterator
is not null, iterate over all T
elements in it and add them to the given Collection
.
Parameter | Description |
---|---|
iteratorFrom | the <code>Iterator</code> to copy from |
collectionTo | the <code>Collection</code> to copy to |
public static <T> void addAll(Iterator<T> iteratorFrom, Collection<T> collectionTo)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { /**//from w w w.ja v a 2 s. com * If the given <code>Iterator</code> is not null, iterate over all <code>T</code> elements * in it and add them to the given <code>Collection</code>. * * @param iteratorFrom the <code>Iterator</code> to copy from * @param collectionTo the <code>Collection</code> to copy to */ public static <T> void addAll(Iterator<T> iteratorFrom, Collection<T> collectionTo) { if (iteratorFrom != null) { while (iteratorFrom.hasNext()) { collectionTo.add(iteratorFrom.next()); } } } }