Java Iterator addAll(Iterator iteratorFrom, Collection collectionTo)

Here you can find the source of addAll(Iterator iteratorFrom, Collection collectionTo)

Description

If the given Iterator is not null, iterate over all T elements in it and add them to the given Collection.

License

Open Source License

Parameter

Parameter Description
iteratorFrom the <code>Iterator</code> to copy from
collectionTo the <code>Collection</code> to copy to

Declaration

public static <T> void addAll(Iterator<T> iteratorFrom,
        Collection<T> collectionTo) 

Method Source Code

//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());
            }
        }
    }
}

Related

  1. addAll(Collection dest, Iterator src)
  2. addAll(Collection dest, Iterator src)
  3. addAll(final C collection, final Iterator iter)
  4. addAll(final Collection targetCollection, final Iterator sourceIterator)
  5. addAll(Iterator source, U target)
  6. addAll(List target, Iterator source)
  7. addAll(Set s, Iterator i)
  8. addAllFromIterator( COLL dest, Iterator source)