public static <A> List<A> toList(Iterator<A> src)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Iterator; public class Main { /**//from ww w . j a v a 2 s.c o m * Creates a List containing all the elements from an Iterator. */ public static <A> List<A> toList(Iterator<A> src) { LinkedList<A> l = new LinkedList<A>(); addAll(l, src); return l; } /** * Adds all the elements from an iterator to a collection. */ public static <A> void addAll(Collection<A> dest, Iterator<? extends A> src) { while (src.hasNext()) dest.add(src.next()); } }