Created
January 15, 2021 13:46
-
-
Save gyselph/2fb0a3f6dddf0bf728e08eff821f9d90 to your computer and use it in GitHub Desktop.
Java 7 to 15: Optional
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Optional.of(new Random().nextInt(10)) | |
.filter(i -> i % 2 == 0) | |
.map(i -> "number is even: " + i) | |
.ifPresent(System.out::println); | |
> number is even: 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment