1z0-809 Exam QuestionsBrowse all questions from this exam

1z0-809 Exam - Question 145


Given:

and the code fragment:

What is the result?

Show Answer
Correct Answer: B

The code first creates a list of Person objects with the specified names and salaries. It then creates a stream from the list and filters the stream to include only those Person objects whose first name starts with 'J'. This results in two Person objects: 'John' with a salary of 2000 and 'Joe' with a salary of 1000. The mapToInt(Person::getSalary) method converts the salaries into an IntStream with values 2000 and 1000. The average() method calculates the average of these salaries, which is 1500.0. Therefore, the correct result is 1500.0.

Discussion

3 comments
Sign in to comment
jduarteOption: B
Apr 9, 2021

answer B. Tested

steefaandOption: B
Feb 7, 2024

B is true.

DarGrinOption: B
Jun 2, 2024

Answer is B. mapToInt() returns an IntStream. average() returns an OptionalDouble. getAsDouble() returns an double