Here you can find the source of toArray(final Iterator> iterator, final int limit)
public static Object[] toArray(final Iterator<?> iterator, final int limit)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; public class Main { public static Object[] toArray(final Iterator<?> iterator, final int limit) { return toArray(iterator, new Object[limit], 0, limit); }//from w ww . j av a 2 s . c o m public static <E> E[] toArray(final Iterator<? extends E> iterator, final E[] array) { for (int i = 0; iterator.hasNext(); i++) { array[i] = iterator.next(); } return array; } public static <E> E[] toArray(final Iterator<? extends E> iterator, final E[] array, final int off) { for (int i = off; iterator.hasNext(); i++) { array[i] = iterator.next(); } return array; } public static <E> E[] toArray(final Iterator<? extends E> iterator, final E[] array, final int off, final int limit) { final int end = off + limit; for (int i = off; (i < end) && iterator.hasNext(); i++) { array[i] = iterator.next(); } return array; } }