Search for data by using search methods of the Stream classes including findFirst, findAny, anyMatch, allMatch, noneMatch.
1. The correct answer is D.
anyMatch()
is a terminal operation, it cannot be linked together with another operation.
2. The correct answer is C.
findAny()
returns Optional<T>
. filter()
is an intermediate operation that returns a new stream. findMatch()
doesn't exists and anyMatch()
returns a boolean
.
3. The correct answer is C.
allMatch()
short-circuits at the first element that doesn't match the given predicate, 1
.
4. The correct answer is A.
filter()
returns a stream of elements starting with 4
. So first, 4
is passed to anyMatch()
, it's printed and since the condition fails, the next element generated by filter()
, 5
, it's passed, which is printed and, since the condition is true
, the whole process is stopped.