1z0-809 Exam QuestionsBrowse all questions from this exam

1z0-809 Exam - Question 125


Given the code fragment:

Which modification enables the code to print Price 5 New Price 4?

Show Answer
Correct Answer: D

The code uses the `peek` method, which is meant for debugging and does not produce a terminal operation that triggers the stream processing. To ensure that the elements are processed and the desired output is printed, the `forEach` method should be used, which is a terminal operation. Replacing line n3 with `.forEach(n -> System.out.println(

Discussion

5 comments
Sign in to comment
jduarteOption: D
Jan 21, 2021

Answer D test

YasinGaberOption: D
Feb 15, 2022

Answer D

aaranetaOption: D
Jul 9, 2023

Answer is D: tested List<Integer> prices = Arrays.asList(3,4,5); prices.stream() .filter(e -> e > 4) .peek(e -> System.out.print("Price " + e)) .map(n -> n - 1) .forEach (n -> System.out.println(" New Price " + n));

steefaandOption: D
Feb 7, 2024

D is correct.

DarGrinOption: D
May 31, 2024

D is correct sinse peek() is not a terminal operation