Created
March 28, 2018 12:59
-
-
Save kunals201/e9fc2d9c1d1263c7768b0c49699c14b2 to your computer and use it in GitHub Desktop.
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
public class IfPresentExample { | |
public static void main(String[] args) { | |
List<Integer> numbers = Arrays.asList(10, 20, 30, 40, 50, 60, 70, 80, 90); | |
Optional<Integer> first = numbers.stream().filter(a -> a > 500).findFirst(); | |
first.ifPresentOrElse( a-> System.out.println(a), () -> System.out.println("")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment