Java Collection to Array toIntArray(Collection coll)

Here you can find the source of toIntArray(Collection coll)

Description

convert the collection to int array.

License

Apache License

Parameter

Parameter Description
coll the integer collection

Return

the int array.

Declaration

public static int[] toIntArray(Collection<Integer> coll) 

Method Source Code

//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;
    }
}

Related

  1. toFloatArray(Collection collection)
  2. toFloatArray(Collection c)
  3. toFloatArray(Collection array)
  4. toFloatArray(final Collection c)
  5. toIntArray(Collection coll)
  6. toIntArray(Collection collection)
  7. toIntArray(Collection collection)
  8. toIntArray(Collection collection)
  9. toIntArray(Collection collection)