helt helt - 1 year ago 98
Java Question

How to convert a Double[] to double...?

Given a method definition:

public void create(double... values);

This method is called like this:

List<Double> values = ...;
Double[] doubles = values.toArray(new Double[0]);
create(doubles); // wont work

Why does it not work?

Answer Source
double[] unboxed = Stream.of(boxed).mapToDouble(Double::doubleValue).toArray();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download