Copies the iterator object into the List(ArrayList) of the specific generic type - Android java.util

Android examples for java.util:Iterator

Description

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

Demo Code


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

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

public class Main {
    /**/*  w w  w  . j  av  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 Tutorials