Java Collection to Array toIntArray(final Collection col)

Here you can find the source of toIntArray(final Collection col)

Description

Convert a collection of int to an array of ints.

License

GNU General Public License

Parameter

Parameter Description
col collection to convert

Return

a new array of ints

Declaration

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

Method Source Code

//package com.java2s;
/*//from  www.  ja  va  2  s. c  o  m
 *                      Nividic development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the ?cole Normale Sup?rieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Nividic project and its aims,
 * or to join the Nividic mailing list, visit the home page
 * at:
 *
 *      http://www.transcriptome.ens.fr/nividic
 *
 */

import java.util.Collection;

public class Main {
    /**
     * Convert a collection of int to an array of ints.
     * @param col collection to convert
     * @return a new array of ints
     */
    public static int[] toIntArray(final Collection<Integer> col) {

        if (col == null)
            return null;

        final int[] result = new int[col.size()];

        int i = 0;
        for (Integer val : col)
            result[i++] = val;

        return result;
    }
}

Related

  1. toIntArray(Collection ints)
  2. toIntArray(Collection list)
  3. toIntArray(Collection list)
  4. toIntArray(Collection values)
  5. toIntArray(final Collection c)
  6. toIntArray(final Collection collection)
  7. toIntArray(final Collection values)
  8. toLongArray(Collection collection)
  9. toLongArray(Collection collection)