Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package java8.streams;
- import java.util.stream.Stream;
- public class ProcessingOrderTest {
- public static void main(String[] args) {
- Stream.of("d2", "a2", "b1", "b3", "c")
- .filter(s -> {
- System.out.println("filter: " + s);
- return true;
- })
- .forEach(s -> System.out.println("forEach: " + s));
- //Reduce the processing by anyMatch instead of filter the order
- Stream.of("d2", "a2", "b1", "b3", "c")
- .map(s -> {
- System.out.println("map: " + s);
- return s.toUpperCase();
- })
- .anyMatch(s -> {
- System.out.println("anyMatch: " + s);
- return s.startsWith("A");
- });
- }
- }
Add Comment
Please, Sign In to add comment