Optional is a container object used to contain not-null objects. Optional object is used to represent null with absent value. This class has various utility methods to facilitate code to handle values as 'available' or 'not available' instead of checking null values.
Is it good to return optional?
When to Not Return Optional. Because Optional is a wrapper and value-based class, there are some operations that can't be done against Optional object. ... Generally speaking, for getters in POJOs, it's more suitable to return the actual type, not an Optional type.
What is the main advantage of optional?
It is used to represent a value is present or absent. The main advantage of this new construct is that No more too many null checks and NullPointerException . It avoids any runtime NullPointerExceptions and supports us in developing clean and neat Java APIs or Applications.