Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { /** * Add all items in iterator to target collection * @param <T> * @param <U> * @param source * @param target * @return */ public static <T, U extends Collection<T>> U addAll(Iterator<T> source, U target) { while (source.hasNext()) { target.add(source.next()); } return target; // for chaining } }