I have a variable like that:
List<Double> frameList = new ArrayList<Double>();
/* Double elements has added to frameList */
How can I have a new variable has a type of double[]
from that variable in Java with high performance?
With java-8, you can do it this way.
double[] arr = frameList.stream().mapToDouble(Double::doubleValue).toArray(); //via method reference
double[] arr = frameList.stream().mapToDouble(d -> d).toArray(); //identity function, Java unboxes automatically to get the double value
What it does is :
Stream<Double>
from the listDoubleStream
toArray()
to get the array.