map() method of Optional object in Java

This method first will check whether our Optional object is empty or not? If not empty, convert its value to another value. Similar to the filter() method, this method returns an Optional object with a value after conversion.

For example:

In the above example, we used the map() method to convert the value of the Optional object to lowercase, then check whether its value contains the letter “k”. If so, print out that value.

You can see more about the filter() method and ifPresent() method of the Optional object to understand more about the example.

Result:

map() method of Optional object in Java

 

Chia sẽ bài viết này ...Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

One thought on “map() method of Optional object in Java

  1. Pingback: Nodejs Example | News | Latest Breaking News Stories & Headlines

Add Comment