Here you can find the source of toPrimitive(Integer[] array)
Parameter | Description |
---|---|
array | the input array, not null |
Parameter | Description |
---|---|
NullPointerException | if array contains null |
public static int[] toPrimitive(Integer[] array)
//package com.java2s; /**/*w w w. j a v a 2s. c o m*/ * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ public class Main { /** * An empty array. */ public static final int[] EMPTY_INT_ARRAY = new int[0]; /** * An empty array. */ public static final long[] EMPTY_LONG_ARRAY = new long[0]; /** * An empty array. */ public static final double[] EMPTY_DOUBLE_ARRAY = new double[0]; /** * Converts a {@code Integer} array to an {@code int} array. * * @param array the input array, not null * @return the output array, not null * @throws NullPointerException if array contains null */ public static int[] toPrimitive(Integer[] array) { if (array.length == 0) { return EMPTY_INT_ARRAY; } int[] result = new int[array.length]; for (int i = 0; i < array.length; i++) { result[i] = array[i]; } return result; } /** * Converts a {@code Long} array to a {@code long} array. * * @param array the input array, not null * @return the output array, not null * @throws NullPointerException if array contains null */ public static long[] toPrimitive(Long[] array) { if (array.length == 0) { return EMPTY_LONG_ARRAY; } long[] result = new long[array.length]; for (int i = 0; i < array.length; i++) { result[i] = array[i]; } return result; } /** * Converts a {@code Double} array to a {@code double} array. * * @param array the input array, not null * @return the output array, not null * @throws NullPointerException if array contains null */ public static double[] toPrimitive(Double[] array) { if (array.length == 0) { return EMPTY_DOUBLE_ARRAY; } double[] result = new double[array.length]; for (int i = 0; i < array.length; i++) { result[i] = array[i]; } return result; } }