Given the code fragment:
List
Predicate
System.out.println("Searching"¦");
return n.contains("red");
};
colors.stream()
.filter(c -> c.length() >= 3)
.allMatch(test);
What is the result?
Given the code fragment:
List
Predicate
System.out.println("Searching"¦");
return n.contains("red");
};
colors.stream()
.filter(c -> c.length() >= 3)
.allMatch(test);
What is the result?
The code initializes a list with three strings and then creates a predicate to test if a string contains 'red'. The stream is filtered to include only strings with a length of at least 3 and then checks if all elements match the predicate. The output of 'allMatch' is short-circuiting, meaning that it stops evaluating as soon as a mismatch is found. In this case, 'red' will match, but 'green' will cause a mismatch and evaluation will stop before checking 'yellow'. Therefore, 'Searching' will be printed twice.
Answer is B-tested
B,tested
B is the correct answer
Answer is B. On second iteration of stream it fails and third iteration isn't run.
Answer is B-tested
Answer is B.