The following code if compiled gives the following error. How to solve this
error: incompatible types: OptionalDouble cannot be converted to Double .average();
Double todaypctpnl = openPositionsdata.stream()
.mapToDouble(c->Double.parseDouble(c.getTodaypctpnl()))
.average();
Did you take a look at the API docs for OptionalDouble?
There are several ways how to convert it back to a double
value, like for example:
double value = OptionalDouble.orElse(-1)
double value = OptionalDouble.orElseThrow(IllegalStateException::new)
etc.
You will have to choose the one fitting best your current needs.
https://docs.oracle.com/javase/tutorial/collections/streams/reduction.html
Double todaypctpnl = openPositionsdata.stream()
.mapToDouble(c->Double.parseDouble(c.getTodaypctpnl()))
.average().getAsDouble();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With