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

Given the code fragment:

List colors = Arrays.asList("red", "green", "yellow");

Predicate test = n - > {

System.out.println("Searching"¦");

return n.contains("red");

};

colors.stream()

.filter(c -> c.length() > 3)

.allMatch(test);

What is the result?

    Correct Answer: B

    The stream first filters elements whose length is greater than 3. This results in two elements: 'green' and 'yellow'. Then, it uses the allMatch method with the Predicate. 'green' and 'yellow' both satisfy the length condition, so the Predicate is applied to both of them. Therefore, 'Searching...' is printed twice.

Discussion
M_JawadOption: A

allMatch is Terminal Short Circuiting operator. All it required is one false A is the answer

adnano1234Option: A

A is correct

jduarteOption: A

Answer is A. Tested

asdfjhfgjuaDCVOption: A

A is the correct answer

steefaandOption: A

Answer is A, tested. Reason for it is that allMatch fails after first call for Predicate and therefore there is no need for additional call(s).

pul26Option: B

Answer is B