简体   繁体   中英

Convert double array to double List array

I have a double array like this:

double[] darr = new double[50];

and I have some elements in it. How can I convert it to a List double array like:

 List<double[]> x = new ArrayList<double[]>();  
double[] darr = new double[50];

If you want a List of double array then you could user Arrays.asList(T...)

List<double[]> darrList = Arrays.asList(darr);

If you want a list of double then you have to create a list, loop over the elements of the array and add each to the list

List<Double> dList = new ArrayList<Double>(darr.length);
for(double d : darr) {
    dList.add(d);
}

好吧,我有正确的答案,只需要做x.add(darr)

If it is possible to use Double[] instead of double[] you can convert it to List<Double> with one command:

Double[] darr = new Double[50];
List<Double> x = Arrays.asList(darr);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM