Here you can find the source of toArray(Collection
Parameter | Description |
---|---|
list | Input list |
public static double[] toArray(Collection<Double> list)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Pablo Pavon-Marino. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html * * Contributors:/*from w w w .j a v a 2 s . c o m*/ * Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1 * Pablo Pavon-Marino - from version 0.4.0 onwards ******************************************************************************/ import java.util.*; public class Main { /** * Converts a collection ({@code List}, {@code Set}...) of {@code Double} objects to a {@code double} array. * * @param list Input list * @return {@code int} array */ public static double[] toArray(Collection<Double> list) { return asPrimitiveArray(list.toArray(new Double[list.size()])); } /** * Converts an array of {@code String} with the values, into a {@code double} array. Uses {@code Double.parseDouble} to parse the number, an can raise the exceptions * that this method raises * * @param list Input list * @return output array */ public static double[] toArray(String[] list) { double[] res = new double[list.length]; int counter = 0; for (String s : list) res[counter++] = Double.parseDouble(s); return res; } /** * Converts from a {@code Double} array to a {@code double} array. * * @param array {@code Double} array * @return Equivalent {@code double} array */ public static double[] asPrimitiveArray(Double[] array) { double[] primitiveArray = new double[array.length]; for (int i = 0; i < array.length; i++) primitiveArray[i] = array[i]; return primitiveArray; } }