Java Iterator asList(final Iterator iterator)

Here you can find the source of asList(final Iterator iterator)

Description

Converts a given iterator in a list.

License

Apache License

Parameter

Parameter Description
T a parameter
iterator the iterator.

Return

a list containing elements found in the iterator.

Declaration

public static <T> List<T> asList(final Iterator<T> iterator) 

Method Source Code

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

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
    /**/*from   w ww.j av  a  2  s  .  co m*/
     * Converts a given iterator in a list.
     * @param <T>
     * 
     * @param iterator the iterator.
     * @return a list containing elements found in the iterator.
     */
    public static <T> List<T> asList(final Iterator<T> iterator) {
        final List<T> result = new ArrayList<T>();
        while (iterator.hasNext()) {
            result.add(iterator.next());
        }

        return result;
    }
}

Related

  1. addTo(final Iterator iter, final C c)
  2. appendTo(final Iterator iter, final List list)
  3. areEqual(final Iterator a, final Iterator b)
  4. areEqual(final Iterator ittyA, final Iterator ittyB)
  5. asArray(T[] arr, Iterator itr)
  6. asList(Iterator it)
  7. asStringOn(StringBuffer sb, Iterator iter, String separator)
  8. cast(Iterator p)
  9. closeIterator(Iterator iterator)