1z0-809 Exam QuestionsBrowse all questions from this exam

1z0-809 Exam - Question 143


Given the code fragment:

Which two code fragments, when inserted at line n1 independently, result in the output PEEK: Unix?

Show Answer
Correct Answer: CE

The code fragment requires an operation that will result in the output 'PEEK: Unix'. The Stream API methods 'findAny()' and 'findFirst()' both return an Optional of an element in the stream, triggering the intermediate operations including 'peek'. Therefore, inserting 'findAny()' or 'findFirst()' at line n1 will result in the expected output. Other methods like 'anyMatch()', 'allMatch()', and 'noneMatch()' require a Predicate and return a boolean, which would not trigger the 'peek' method in the same way.

Discussion

3 comments
Sign in to comment
laura_lu93Options: CE
Mar 11, 2021

answer is C and E. tested (anyMatch and noneMatch need an arguments predicate)

steefaandOptions: CE
Feb 7, 2024

C and E are correct. Other options require Predicate.

DarGrinOptions: CE
Jun 2, 2024

allMatch, anyMatch, noneMatch take a Predicate and return boolean. So the answer is C and E