Exam 1z0-816 All QuestionsBrowse all questions from this exam
Question 14

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.)

    Correct Answer: B, E

    To calculate the average of a list of numbers using Java streams, we need to convert the list to a stream and use appropriate methods to compute the average. Option B uses 'parallelStream()', maps the elements to integers, and then calculates the average correctly using '.average().getAsDouble()'. Option E correctly uses 'stream().collect(Collectors.averagingDouble(n -> n))' to collect the stream and compute the average as a double. These two codes will accomplish the task correctly.

Discussion
Sa16253748596Options: BE

B,E is true