Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static final long[] EMPTY_LONG_ARRAY = new long[0]; public static final int[] EMPTY_INT_ARRAY = new int[0]; public static final double[] EMPTY_DOUBLE_ARRAY = new double[0]; public static final boolean[] EMPTY_BOOLEAN_ARRAY = new boolean[0]; public static long[] toPrimitive(final Long[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_LONG_ARRAY; } final long[] result = new long[array.length]; for (int i = 0; i < array.length; i++) { result[i] = array[i].longValue(); } return result; } public static long[] toPrimitive(final Long[] array, final long valueForNull) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_LONG_ARRAY; } final long[] result = new long[array.length]; for (int i = 0; i < array.length; i++) { final Long b = array[i]; result[i] = (b == null ? valueForNull : b.longValue()); } return result; } public static int[] toPrimitive(final Integer[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_INT_ARRAY; } final int[] result = new int[array.length]; for (int i = 0; i < array.length; i++) { result[i] = array[i].intValue(); } return result; } public static int[] toPrimitive(final Integer[] array, final int valueForNull) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_INT_ARRAY; } final int[] result = new int[array.length]; for (int i = 0; i < array.length; i++) { final Integer b = array[i]; result[i] = (b == null ? valueForNull : b.intValue()); } return result; } public static double[] toPrimitive(final Double[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_DOUBLE_ARRAY; } final double[] result = new double[array.length]; for (int i = 0; i < array.length; i++) { result[i] = array[i].doubleValue(); } return result; } public static double[] toPrimitive(final Double[] array, final double valueForNull) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_DOUBLE_ARRAY; } final double[] result = new double[array.length]; for (int i = 0; i < array.length; i++) { final Double b = array[i]; result[i] = (b == null ? valueForNull : b.doubleValue()); } return result; } public static boolean[] toPrimitive(final Boolean[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_BOOLEAN_ARRAY; } final boolean[] result = new boolean[array.length]; for (int i = 0; i < array.length; i++) { result[i] = array[i].booleanValue(); } return result; } public static boolean[] toPrimitive(final Boolean[] array, final boolean valueForNull) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_BOOLEAN_ARRAY; } final boolean[] result = new boolean[array.length]; for (int i = 0; i < array.length; i++) { final Boolean b = array[i]; result[i] = (b == null ? valueForNull : b.booleanValue()); } return result; } }