Looking for a way to chain optionals so that the first one that is present is returned. If none are present Optional.empty() should be returned.
Assumi
To perform Optional Chaining First convert Stream to Optional Using either of the two methods
Once optional is obtained optional has two more instance method which are also present in Stream class i.e filter and map(). use these on methods and to check output use ifPresent(System.out :: Println)
ex:
Stream s = Stream.of(1,2,3,4);
s.findFirst().filter((a)->a+1).ifPresent(System.out :: Println)
Output is : 2