Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 125

Given the code fragment:

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

    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
jduarteOption: D

Answer D test

YasinGaberOption: D

Answer D

DarGrinOption: D

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

steefaandOption: D

D is correct.

aaranetaOption: D

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