Here you can find the source of fill(final Iterator
public static final <S extends Collection<T>, T> S fill(final Iterator<T> iterator, final S collection)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { public static final <S extends Collection<T>, T> S fill(final Iterator<T> iterator, final S collection) { while (iterator.hasNext()) { collection.add(iterator.next()); }// ww w.ja va 2s .c om return collection; } }