filmov
tv
Java Optional Tutorial - How to Use Optional Class In Java
![preview_player](https://i.ytimg.com/vi/PlOSuPVNy7k/maxresdefault.jpg)
Показать описание
Java 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. - Java Docs
The Java Optional class was introduced in Java 8 but has been improved ever since with new methods. We can use it to prevent null pointer exceptions (nullpointerexceptions).
An Optional can either be in two states, have a value present or empty state.
You can use Java Optionals to avoid null checks, we can check is an Optional has a value by calling isPresent method.
To assign a value to an Optional we can use the of or ofNullable method.
of: Returns an Optional with the specified present non-null value. - (Java Docs)
ofNullable: Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional. - (Java Docs)
TimeStamps 🕰 :
00:00 The Need For Optionals
03:36 Creating New Optional
07:28 Optional isPresent and isEmpty
12:15 Optional orElse
16:52 Optional Map
20:10 Optional Filter
23:20 Optional ifPresent
25:51 Optional of NonNull Return
31:30 Optional of Nullable Return
Connect With Lemubit Academy And Lemuel Ogbunude 🔍:
The Java Optional class was introduced in Java 8 but has been improved ever since with new methods. We can use it to prevent null pointer exceptions (nullpointerexceptions).
An Optional can either be in two states, have a value present or empty state.
You can use Java Optionals to avoid null checks, we can check is an Optional has a value by calling isPresent method.
To assign a value to an Optional we can use the of or ofNullable method.
of: Returns an Optional with the specified present non-null value. - (Java Docs)
ofNullable: Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional. - (Java Docs)
TimeStamps 🕰 :
00:00 The Need For Optionals
03:36 Creating New Optional
07:28 Optional isPresent and isEmpty
12:15 Optional orElse
16:52 Optional Map
20:10 Optional Filter
23:20 Optional ifPresent
25:51 Optional of NonNull Return
31:30 Optional of Nullable Return
Connect With Lemubit Academy And Lemuel Ogbunude 🔍:
Комментарии