Java Primitive Type Create toPrimitive(final Double[] arr)

Here you can find the source of toPrimitive(final Double[] arr)

Description

Returns a double array containing the double representation of given Double array.

License

Open Source License

Parameter

Parameter Description
arr Double array to convert to double array

Return

a double array containing the double representation of given array

Declaration

public static double[] toPrimitive(final Double[] arr) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015, 2017 Lablicate GmbH.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  ww  w. ja  v a 2  s .  c  o m*/
 * Dr. Alexander Kerner - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     *
     * Returns a {@code double} array containing the {@code double} representation of given {@link Double} array.
     * </p>
     * Note: {@code null values} in {@code arr} are ignored! Length of returned array
     * may be less than length of input array therefore.
     *
     * @param arr
     *            {@link Double} array to convert to {@code double} array
     * @return a {@code double} array containing the {@code double} representation of given {@link Double} array
     */
    public static double[] toPrimitive(final Double[] arr) {

        final double[] result = new double[arr.length];
        for (int i = 0; i < arr.length; i++)
            result[i] = arr[i];
        return result;
    }

    /**
     *
     * Returns a {@code int} array containing the {@code int} representation of
     * given {@link Integer} array.
     * </p>
     * Note: {@code null values} in {@code arr} are ignored! Length of returned array may be less than length
     * of input array therefore.
     *
     * @param arr
     *            {@link Integer} array to convert to {@code int} array
     * @return a {@code int} array containing the {@code int} representation of
     *         given {@link Integer} array
     */
    public static int[] toPrimitive(final Integer[] arr) {

        final int[] result = new int[arr.length];
        for (int i = 0; i < arr.length; i++)
            if (arr[i] != null) {
                result[i] = arr[i];
            }
        return result;
    }

    /**
     *
     * Returns a {@code double} array containing the {@code double} representation of given {@link Number} array.
     * </p>
     * Note: {@code null values} in {@code arr} are ignored! Length of returned array
     * may be less than length of input array therefore.
     *
     * @param arr
     *            {@link Number} array to convert to {@code double} array
     * @return a {@code double} array containing the {@code double} representation of given {@link Number} array
     */
    public static double[] toPrimitive(final Number[] arr) {

        final double[] result = new double[arr.length];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != null) {
                result[i] = arr[i].doubleValue();
            }
        }
        return result;
    }
}

Related

  1. toPrimitive(Double[] array)
  2. toPrimitive(Double[] doubles)
  3. toPrimitive(Double[] vals)
  4. toPrimitive(final Boolean b)
  5. toPrimitive(final Character value, final char defaultValue)
  6. toPrimitive(Float[] floats)
  7. toPrimitive(Integer[] array)
  8. toPrimitive(Integer[] IntArray)
  9. toPrimitive(Integer[] ints)