Optional

suggest change

Versions

java.util.Optional was added in Java SE 8.

Introduction

Optional is a container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.

Additional methods that depend on the presence of the contained value are provided, such as orElse(), which returns a default value if the value is not present, and ifPresent(), which executes a block of code if the value is present.

Syntax

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents