Choose the best option based on this program:
import java.util.stream.Stream; public class Main { public static void main(String []args) { boolean result = Stream.of("do", "re", "mi", "fa", "so", "la", "ti") .filter(str -> str.length() > 5) // #1 .peek(System.out::println) // #2 .allMatch(str -> str.length() > 5); // #3 System.out.println(result); }//from ww w.j a v a 2 s . c o m }
F.
the predicate str -> str.length()
> 5 returns false for all the elements because the length of each string is 2.
hence, the filter()
method results in an empty stream and the peek()
method does not print anything.
the allMatch()
method returns true for an empty stream and does not evaluate the given predicate.
hence this program prints true.