Oracle Certified Professional Java Se 8 Programmer · Free Practice Question Hard

Question 22

Given code of Test.java file: 

What will be the result of compiling and executing Test class?

  • A Compilation error
  • B HELLO
  • C

    Program executes successfully but nothing is printed on to the console

Reveal correct answer

Correct answer: C

Explanation

Method signature for anyMatch method:

boolean anyMatch(Predicate<? super T>) : Returns true if any of the stream element matches the given Predicate.

If stream is empty, it returns false and predicate is not evaluated.


As given stream is empty, hence predicate is not evaluated and nothing is printed on to the console.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need