Java examples for java.util:Iterator
iterator To List
//package com.java2s; import java.util.*; public class Main { public static void main(String[] argv) { Iterator iterator = java.util.Arrays.asList("asdf", "java2s.com") .iterator();/*from w w w . jav a 2 s .c om*/ System.out.println(iteratorToList(iterator)); } public static <T> List<T> iteratorToList(final Iterator<T> iterator) { List<T> list = new ArrayList<T>(); for (T element : new Iterable<T>() { public Iterator<T> iterator() { return iterator; } }) { list.add(element); } return list; } }