Given the code fragment:
List
Function
.map(funVal)
.peek(System.out::print);
What is the result?
Given the code fragment:
List
Function
.map(funVal)
.peek(System.out::print);
What is the result?
The code fragment contains a compilation error due to the incorrect use of the 'contact' method. The correct method should be 'concat'. Since 'contact' is not a valid method for String, it will not compile.
Correct answer is C, since peek is an intermediate lazy operation which will not be evaluated unless the pipeline is ended with a terminating operation.
Correct answer is C.If we replace peek with forEach answer is A
it prints nothing. if we change peek to forEach, the output would be Hello : JimHello : JohnHello : Jeff
Answer is C. Tested.
Answer is C. if we use any terminal operation after peek like .count()( even though its bad o/p formatting) then the answer would be A.
C is the correct answer:tested
C is correct, since there is no terminal operation and Stream is never run.
Answer is A tested: class Testing { public static void main (String[] args) throws IOException{ List<String> nL = Arrays.asList("Jim ", "John ", "Jeff"); Function<String, String> funVal = s -> "Hello : ".concat(s); nL.stream() .map(funVal) .forEach(s-> System.out.print (s)); } } output: Hello : Jim Hello : John Hello : Jeff
there is no terminal operation .forEach() that was called
The Correct Answer should be D; If ignore the typo of "Hello : ".contact(s), C is the correct answer
D is correct. We have no String.contact method
it is String.concat