package util; import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Iterator; public class CollectionUtil { /** * Adds all the elements from an iterator to a collection. */ public static void addAll(Collection dest, Iterator src) { while (src.hasNext()) dest.add(src.next()); } /** * Creates a List containing all the elements from an Iterator. */ public static List toList(Iterator src) { LinkedList l = new LinkedList(); addAll(l, src); return l; } /** * Gets all the elements from an iterator and does nothing with them. */ public static void getAll(Iterator it) { while (it.hasNext()) it.next(); } }