Optional class is a nice solution that can be used to solve NullPointerException problem or in such cases when you need to express an empty value. In other words, it can be compared with a box that might contain something or be empty.
The class was introduced in Java 8 and you can see that it’s widely used in Stream API. For instance, such methods like min, max and average return Optional. Since the stream source can be empty it’s better to return Optional rather than null. Because Optional class provides rich functionality to handle different scenarios in functional way. Continue reading Optional Class Overview