Java Iterator addAll(final Collection targetCollection, final Iterator sourceIterator)

Here you can find the source of addAll(final Collection targetCollection, final Iterator sourceIterator)

Description

Adds all elements that a given Iterator provides to a given Collection of appropriate type

License

Apache License

Parameter

Parameter Description
targetCollection the Collection where to add the elements
sourceIterator the Iterator where to get the elements from
T the type of elements to transfer

Declaration

public static <T> void addAll(final Collection<? super T> targetCollection,
        final Iterator<? extends T> sourceIterator) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Collection;
import java.util.Iterator;

public class Main {
    /**/*from   w w  w  . j a va2  s  . c o  m*/
     * Adds all elements that a given {@link Iterator} provides to a given
     * {@link Collection} of appropriate type
     * 
     * @param targetCollection
     *           the {@link Collection} where to add the elements
     * @param sourceIterator
     *           the {@link Iterator} where to get the elements from
     * @param <T>
     *           the type of elements to transfer
     */
    public static <T> void addAll(final Collection<? super T> targetCollection,
            final Iterator<? extends T> sourceIterator) {
        while (sourceIterator.hasNext()) {
            targetCollection.add(sourceIterator.next());
        }
    }
}

Related

  1. addAll(Collection dest, Iterator src)
  2. addAll(Collection dest, Iterator src)
  3. addAll(final C collection, final Iterator iter)
  4. addAll(Iterator iteratorFrom, Collection collectionTo)
  5. addAll(Iterator source, U target)
  6. addAll(List target, Iterator source)
  7. addAll(Set s, Iterator i)