I have a method that builds a list and I want it to return the average of the list as an Optional value.
However, when I calculate the average value using Java 8, I always get the return value as an OptionalDouble.
How do I convert
OptionalDouble to Optional<Double>?
Below are my code for average calculation:
private static Optional<Double> averageListValue() {
// Build list
List<Double> testList = new ArrayList<>();
testList.add(...);
...
...
return testList.stream().mapToDouble(value -> value).average();
}
Thanks.