Oracle Certified Professional Java Se 11 Developer · Free Practice Question Easy

Question 17

Question ID: UKOCP69133


Given code:


What is the result?

  • A null
  • B 0
  • C -1
  • D Optional.empty
Reveal correct answer

Correct answer: C

Explanation

UKOCP69133:

Stream.of() creates an empty stream.

stream.findFirst(); => returns an empty Optional. Hence, orElse method is executed and prints -1 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