Given the code fragment:
List<String> nL = Arrays.asList(“Jim”, “John”, “Jeff”);
Function<String, String> funVal = s -> “Hello : “.contact(s);
nL.Stream()
.map(funVal)
.peek(System.out::print);
What is the result?
A.
Hello : Jim Hello : John Hello : Jeff
B.
Jim John Jeff
C.
The program prints nothing.
D.
A compilation error occurs.
D.
But if the contact method is concat method and the Stream method is stream method, the answer would be C.
same answer by me also. D
C.
The “contact” method is just a typo in this particular dump.
The real trick is in the peek method.
C
C. if we correct contact() to concat() and Stream() to stream().
D. if question is not corrected.
A. if we change terminal code .peek() to .forEach().
C.
It compiles, but there is no terminal operation for the stream. The program prints nothing.
C