Given:
and the code fragment:What is the result?
Given:
and the code fragment:What is the result?
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.
answer B. Tested
Answer is B. mapToInt() returns an IntStream. average() returns an OptionalDouble. getAsDouble() returns an double
B is true.