Here you can find the source of getSomeElements(Iterator
public static <T> List<T> getSomeElements(Iterator<T> iterator, int limit)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static <T> List<T> getSomeElements(Iterator<T> iterator, int limit) { ArrayList<T> list = new ArrayList<>(); int currentAmount = 0; while (iterator.hasNext() && (currentAmount++ < limit)) { list.add(iterator.next());/*from ww w.java 2s . c o m*/ } return list; } }