I have stream of optionals. I would like to return true if any of elemeents of the stream is not present and false if all elements are present.
The code:
return Stream.of(a.getBestArrivalTime(),
a.getBestDepartureTime(),
a.getScheduledArrivalTime(),
a.getScheduledDepartureTime())
.anyMatch(Objects::isNull);
It checks whether elements are null, but it is wrong because it does not work on optionals variables. I think I need to use Optional::isPresent
, but I could not use it because Stream.of()
is a static method.
The fields in the stream are just chosen fields from the object.