Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; public class Main { public static long[] toArray(Iterator<Long> it) { List<Long> list = toList(it); return toArray(list); } public static long[] toArray(Collection<Long> collection) { long[] array = new long[collection.size()]; Iterator<Long> it = collection.iterator(); int i = 0; while (it.hasNext()) { array[i++] = it.next(); } return array; } public static List<Long> toList(Iterator<Long> it) { List<Long> list = new ArrayList<Long>(); while (it.hasNext()) { list.add(it.next()); } return list; } }