Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kunals201
Created March 28, 2018 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunals201/e9fc2d9c1d1263c7768b0c49699c14b2 to your computer and use it in GitHub Desktop.
Save kunals201/e9fc2d9c1d1263c7768b0c49699c14b2 to your computer and use it in GitHub Desktop.
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