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 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.
allMatch is Terminal Short Circuiting operator. All it required is one false A is the answer
A is correct
Answer is A. Tested
A is the correct answer
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).
Answer is B