Given the code fragment:
Which modification enables the code to print Price 5 New Price 4?
Given the code fragment:
Which modification enables the code to print Price 5 New Price 4?
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(
Answer D test
Answer D
D is correct sinse peek() is not a terminal operation
D is correct.
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));