Here you can find the source of copyOf(Iterator extends E> elements)
public static <E> List<E> copyOf(Iterator<? extends E> elements)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static <E> List<E> copyOf(Iterator<? extends E> elements) { if (elements == null) { return null; }/*ww w . j a v a2 s. c o m*/ if (!elements.hasNext()) { return Collections.emptyList(); } List<E> list = new ArrayList<>(); while (elements.hasNext()) { list.add(elements.next()); } return Collections.unmodifiableList(list); } }