What is the result?

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?

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.



Leave a Reply 7

Your email address will not be published. Required fields are marked *


KashiHide

KashiHide

D.

But if the contact method is concat method and the Stream method is stream method, the answer would be C.

smh

smh

same answer by me also. D

DG

DG

C.
The “contact” method is just a typo in this particular dump.
The real trick is in the peek method.

smh

smh

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().

andrei

andrei

C.
It compiles, but there is no terminal operation for the stream. The program prints nothing.