Android Iterator to List Convert copyIterator(Iterator iter)

Here you can find the source of copyIterator(Iterator iter)

Description

Copies the iterator object into the List(ArrayList) of the specific generic type

Parameter

Parameter Description
iter a parameter

Declaration

public static <T> List<T> copyIterator(Iterator<T> iter) 

Method Source Code

//package com.java2s;
import java.util.ArrayList;

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

public class Main {
    /**/*from   w w w .  ja  v  a  2 s .  c  o m*/
     * Copies the iterator object into the List(ArrayList) of the specific generic type 
     * @param iter
     * @return
     */
    public static <T> List<T> copyIterator(Iterator<T> iter) {
        List<T> copy = new ArrayList<T>();
        while (iter.hasNext())
            copy.add(iter.next());
        return copy;
    }
}

Related

  1. addToList(Iterator itor, List list)