Method ofNullable() of Stream object in Java

This method was added from Java 9.

This method will return the Stream object of an element in case this element is not null; if it is null, it returns an empty Stream.

Example:

When you run the above code, it will print nothing in the console. But if you edit the variable s, not null:

then the result will be:

Method ofNullable() of Stream object in Java

 

Add Comment