Java examples for java.util:Iterable Convert
Copy Iterator to List
//package com.java2s; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static void main(String[] argv) { Iterator iter = java.util.Arrays.asList("asdf", "java2s.com") .iterator();//w w w. j av a 2s .co m System.out.println(copyIterator(iter)); } /** * Iterator to List * @param <T> * @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; } }