Here you can find the source of toList(Iterator
public static <T> List<T> toList(Iterator<T> it)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static <T> List<T> toList(Iterator<T> it) { List<T> l = new ArrayList<T>(); while (it.hasNext()) { l.add(it.next());// w w w .j a va2 s . c o m } return l; } }