Here you can find the source of toIntArray(Collection
Parameter | Description |
---|---|
coll | the integer collection |
public static int[] toIntArray(Collection<Integer> coll)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { /**//from w ww . ja v a 2s . c o m * convert the collection to int array. * @param coll the integer collection * @return the int array. */ public static int[] toIntArray(Collection<Integer> coll) { if (coll == null || coll.isEmpty()) { return null; } final int[] arr = new int[coll.size()]; final Iterator<Integer> it = coll.iterator(); int i = 0; for (; it.hasNext();) { arr[i++] = it.next(); } return arr; } }