Which can fill in the blank so this code outputs true?
import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) { Stream<Boolean> hide = Stream.of(true, false, true); Predicate<Boolean> pred = b -> b; boolean found = hide.filter(pred).___(pred); System.out.println(found); } /* ww w. j a v a 2s. c om*/ }
anyMatch()
allMatch()
anyMatch()
and allMatch()
noneMatch()
C.
The filter()
method passes two of the three elements of the stream through to the terminal operation.
This is redundant since the terminal operation checks the same Predicate.
There are two matches with the same value, so both anyMatch()
and allMatch()
return true, and Option C is correct.