Here you can find the source of toArray(final Collection
public static int[] toArray(final Collection<Integer> collection)
//package com.java2s; import java.util.Collection; public class Main { public static int[] toArray(final Collection<Integer> collection) { if (collection == null || collection.isEmpty()) { return new int[0]; }//from w ww . j a v a 2 s .com final int[] result = new int[collection.size()]; int index = 0; for (final Integer integer : collection) { result[index] = integer.intValue(); index++; } return result; } }