Java List to Primitive Array toPrimitiveArray(List array)

Here you can find the source of toPrimitiveArray(List array)

Description

to Primitive Array

License

Open Source License

Declaration

public static double[] toPrimitiveArray(List<Double> array) 

Method Source Code

//package com.java2s;
/**//from  www  . j  av a2 s  . c  o  m
 * Copyright (c) 2014 Xiufeng Liu ( xiufeng.liu@uwaterloo.ca )
 * <p/>
 * This file is free software: you may copy, redistribute and/or modify it
 * under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 * <p/>
 * This file is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * <p/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses.
 */

import java.util.*;

public class Main {
    public static double[] toPrimitiveArray(List<Double> array) {
        double[] primitiveArray = new double[array.size()];
        for (int i = 0; i < array.size(); ++i) {
            primitiveArray[i] = array.get(i).doubleValue();
        }
        return primitiveArray;
    }

    public static double[] toPrimitiveArray(Double[] array) {
        if (array == null)
            return null;
        double[] primitiveArray = new double[array.length];
        for (int i = 0; i < array.length; ++i) {
            if (array[i] == null)
                return null;
            primitiveArray[i] = array[i].doubleValue();
        }
        return primitiveArray;
    }

    public static int[] toPrimitiveArray(Integer[] array) {
        int[] primitiveArray = new int[array.length];
        for (int i = 0; i < array.length; ++i) {
            primitiveArray[i] = array[i].intValue();
        }
        return primitiveArray;
    }
}

Related

  1. toPrimitiveArray(List input)
  2. toPrimitiveArray(List list)
  3. toPrimitiveArray(List target_)
  4. toPrimitivebyList(List list)