0 votes
in JAVA by
Which of the following is true about the Optional.orElse() method in Java 8?

a) It returns the value of the Optional if present, or throws an exception if not.

b) It returns the value of the Optional if present, or the specified default value if not.

c) It returns true if the Optional contains a value, and false otherwise.

d) It returns the value of the Optional if present, or an empty Optional if not.

1 Answer

0 votes
by
Answer: b) It returns the value of the Optional if present, or the specified default value if not.

Explanation: The Optional.orElse() method returns the value of the Optional if present, or the specified default value if not.
...