How can I convert List <List <Double>> to List <Double []> and enumerate <double []> using Java 8 Stream API?
I am stuck with this issue. I found similar answers here, but none of them solve the problem. Should I use mapToDouble () here? Is there something like "mapToDoubleArray"?
To convert a List<List<Double>>
to List<double[]>
, you need to map each inner list to a double array using mapToDouble
in conjunction with toArray()
(which is the "mapToDoubleArray" operation you are looking for).
List<double[]> res =
myList.stream()
.map(l -> l.stream().mapToDouble(d -> d).toArray())
.collect(toList());
If you want instead List<double[]>
, you can just use .map(list -> list.toArray(new Double[list.size()]))
.