Here you can find the source of toDoubleArray(String array)
String should have the format "[1.2,2.6,3]"
Parameter | Description |
---|---|
array | the string to be casted |
public static double[] toDoubleArray(String array)
//package com.java2s; //License from project: Open Source License public class Main { /**/* www . j a v a 2 s .c om*/ * Cast a string to an array of double * <p> * String should have the format <code>"[1.2,2.6,3]"</code> * * @param array * the string to be casted * @return an array containing the parsed double */ public static double[] toDoubleArray(String array) { // Empty array [] if (array.length() == 2) return new double[0]; String[] cast = array.substring(1, array.length() - 1).split(","); double[] result = new double[cast.length]; for (int i = 0; i < cast.length; i++) { result[i] = Double.valueOf(cast[i]); } return result; } }