Created
October 17, 2023 11:30
-
-
Save truongquoc/72459ee610ce1d8c77ddb9f191c61dd9 to your computer and use it in GitHub Desktop.
stream API
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 void lazyEvaluate() { | |
List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | |
long count = numbers.stream() | |
.filter(n -> { | |
System.out.println("Filtering: " + n); | |
return n % 2 == 0; | |
}) | |
.map(n -> { | |
System.out.println("Mapping: " + n); | |
return n * 2; | |
}) | |
.peek(n -> System.out.println("Peeking: " + n)) | |
.collect(Collectors.counting()); | |
System.out.println("Total count of even numbers: " + count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment