Here you can find the source of toList(Iterator> iterator)
public static List<?> toList(Iterator<?> iterator)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { /**/* w w w .j a v a 2 s . com*/ * @param selection * @return */ public static List<?> toList(Object[] objs) { ArrayList<Object> ret = new ArrayList<Object>(); if (objs != null) for (int i = 0; i < objs.length; i++) ret.add(objs[i]); return ret; } /** * @param selection * @return */ public static List<Integer> toList(int[] objs) { List<Integer> ret = new ArrayList<Integer>(); if (objs != null) for (int i = 0; i < objs.length; i++) ret.add(objs[i]); return ret; } public static List<?> toList(Iterator<?> iterator) { ArrayList<Object> ret = new ArrayList<Object>(); while (iterator.hasNext()) ret.add(iterator.next()); return ret; } }