Java Iterator from getList(Iterator iterator)

Here you can find the source of getList(Iterator iterator)

Description

Creates a list of all of the items in an iteration.

License

Apache License

Parameter

Parameter Description
iterator a parameter

Declaration

public static List<String> getList(Iterator<String> iterator) 

Method Source Code

//package com.java2s;
/*//from w w w.  j av  a2  s . c o  m
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 *     http://duracloud.org/license/
 */

import java.util.ArrayList;

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

public class Main {
    /**
     * Creates a list of all of the items in an iteration.
     * Be wary of using this for Iterations of very long lists.
     *
     * @param iterator
     * @return
     */
    public static List<String> getList(Iterator<String> iterator) {
        List<String> contents = new ArrayList<String>();
        while (iterator.hasNext()) {
            contents.add(iterator.next());
        }
        return contents;
    }
}

Related

  1. getIterator(List list)
  2. getIterator(T[] array)
  3. getIteratorAsString(Iterator iter, final String separator)
  4. getIteratorOptionalValue(final Iterator stringIterator)
  5. getLast(Iterator iterator)
  6. getMaxLength(Iterator i)
  7. getPerplexity(Iterator probStream)
  8. getPersistentKeysIterator(HashMap hashMap)
  9. getSigLinePastOtherAnnotations(String selfCmprurrentLine, Iterator line_itr)