Given the code fragment:
Which two code fragments, when inserted at line n1 independently, result in the output PEEK: Unix?
Given the code fragment:
Which two code fragments, when inserted at line n1 independently, result in the output PEEK: Unix?
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.
answer is C and E. tested (anyMatch and noneMatch need an arguments predicate)
allMatch, anyMatch, noneMatch take a Predicate and return boolean. So the answer is C and E
C and E are correct. Other options require Predicate.