An empty optional is the main way to avoid the Null Pointer Exception when using the Optional API.
In Optional’s flow, a null will be transformed into an empty Optional. The empty Optional won’t be processed any further. This is how we can avoid a NullPointerException when using Optional.
We will learn further about how an empty Optional behaves later in this article.