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

Given the code fragment:

List nL = Arrays.asList("Jim", "John", "Jeff");

Function funVal = s -> "Hello : ".contact(s); nL.Stream()

.map(funVal)

.peek(System.out::print);

What is the result?

    Correct Answer: D

    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.

Discussion
speed045Option: C

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.

Svetleto13Option: C

Correct answer is C.If we replace peek with forEach answer is A

InnovationOption: C

it prints nothing. if we change peek to forEach, the output would be Hello : JimHello : JohnHello : Jeff

thetechOption: C

Answer is C. Tested.

nikhil_3011Option: C

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.

asdfjhfgjuaDCVOption: C

C is the correct answer:tested

steefaandOption: C

C is correct, since there is no terminal operation and Stream is never run.

ayzoOption: A

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

pridemore

there is no terminal operation .forEach() that was called

johnchen88Option: D

The Correct Answer should be D; If ignore the typo of "Hello : ".contact(s), C is the correct answer

DestroyerOption: D

D is correct. We have no String.contact method

M_Jawad

it is String.concat