Hi I am using Java Optional. I saw that the Optional has a method ifPresent.
Instead of doing something like:
Optional object = someMeth
.findFirst() returns a Optional, but if we add .orElse(null) it returns the get of the optional if isPresent(), that is (MyType), or otherwise a NULL
.findFirst()
Optional
.orElse(null)
isPresent()
MyType
NULL
MyType s = newList.stream().filter(d -> d.num == 0).findFirst().orElse(null);