Java SE 11 Developer — Question 23

var numbers = List.of(0,1,2,3,4,5,6,7,8,9);
You want to calculate the average of numbers.
Which two codes will accomplish this? (Choose two.)

Answer options

Correct answer: B, D

Explanation

Option B is correct because it uses parallelStream and mapToInt to calculate the average properly. Option D is incorrect because the stream method does not have a direct average() method that returns a double, while the correct way to retrieve the average must involve a call to getAsDouble().