java - How to create List<Double> fromapache's common math DescriptiveStatistics<Double>? -


i have variable descriptivestatistics stats create double array. using following code:

import org.apache.commons.math3.stat.descriptive.descriptivestatistics; //... descriptivestatistics stats; //... arrays.aslist(stats.getvalues()) 

i list<double[]> not list<double>. stats.getvalues() returns double[].

how can fix , list<double> descriptivestatistics ?

as per method signature of arrays.aslist() returns list of type passed in arguments.

public static <t> list<t> aslist(t... a) 

for example:

double[] array=new double[]{1,2,3}; list<double[]> list=arrays.aslist(array); // here t `double[]` list of size 1  ...  double[][] array = new double[][] { { 1, 2, 3 }, { 4, 5, 6 } }; list<double[]> list=arrays.aslist(array); // here t `double[]` list of size 2  ...  list<double> list=arrays.aslist(1.0,2.0,3.0); // here t double list of size 3 

root cause:

since array object , in case double[] treated single object, not array of double per generic hence list<double[]> returned instead of list<double>.

solution 1

you can solve simple classic code:

double[] array = new double[] { 1, 2, 3 }; list<double> list = new arraylist<double>(); (double d : array) {     list.add(d); } 

solution 2

simply change return type of method stats.getvalues() double[] double[]

double[] array = new double[] { 1.0, 2.0, 3.0 }; list<double> list = arrays.aslist(array); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -