Here you can find the source of addToCollection(Iterator
private static <T> Collection<T> addToCollection(Iterator<T> iterator, Collection<T> collection)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Collections; import java.util.Iterator; public class Main { private static <T> Collection<T> addToCollection(Iterator<T> iterator, Collection<T> collection) { while (iterator.hasNext()) { T object = iterator.next();/*from w w w. jav a 2s . co m*/ collection.add(object); } return Collections.unmodifiableCollection(collection); } }