Here you can find the source of toSet(Iterator extends T> iteration)
public static <T> Set<T> toSet(Iterator<? extends T> iteration)
//package com.java2s; import java.util.*; public class Main { public static <T> Set<T> toSet(Iterator<? extends T> iteration) { Set<T> elements = new HashSet<T>(1); while (iteration.hasNext()) { elements.add(iteration.next()); }/*from w w w. ja va 2 s .c om*/ return elements; } }