Java Iterator toCollection(final Iterator iterator, final Collection c)

Here you can find the source of toCollection(final Iterator iterator, final Collection c)

Description

to Collection

License

Open Source License

Declaration

public static <E> void toCollection(final Iterator<E> iterator, final Collection<? super E> c) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static <E> void toCollection(final Iterator<E> iterator, final Collection<? super E> c) {
        while (iterator.hasNext()) {
            c.add(iterator.next());/*  w w w  . ja v  a 2  s .  co  m*/
        }
    }

    public static <E> void toCollection(final Iterator<? extends E> iterator, final Collection<? super E> c,
            final int limit) {
        for (int i = 0; (i < limit) && iterator.hasNext(); i++) {
            c.add(iterator.next());
        }
    }
}

Related

  1. singletonIterator(final T nullableValue)
  2. singletonIterator(final T t)
  3. size(Iterator iterator)
  4. splice(LinkedList list, Iterator iterator, LinkedList list2, V v)
  5. toArray(final Iterator iterator)
  6. toCommaSeparatedString(Iterator i)
  7. toIterator(Collection col)
  8. toIterator(final T[] data)
  9. toMap(final Iterator> iterator)