Method to convert a Array Collection of Integer to a Array Collection of int. - Java Collection Framework

Java examples for Collection Framework:Array Convert

Description

Method to convert a Array Collection of Integer to a Array Collection of int.

Demo Code


//package com.book2s;

public class Main {
    /**//from  w ww  . jav  a  2s  . c o  m
     * Method to convert a Array Collection of Integer to a Array Collection of int.
     * @param integerArray the Array Collection of Integers.
     * @return Array Collection of int.
     */
    public static int[] toPrimitive(Integer[] integerArray) {
        //return org.apache.commons.lang3.ArrayUtils.toPrimitive(integerArray);
        if (integerArray == null)
            return null;
        else if (integerArray.length == 0)
            return new int[0];
        final int[] result = new int[integerArray.length];
        for (int i = 0; i < integerArray.length; i++) {
            result[i] = integerArray[i];
        }
        return result;
    }
}

Related Tutorials