Guest User

Untitled

a guest
Dec 15th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. package java8.streams;
  2.  
  3. import java.util.stream.Stream;
  4.  
  5. public class ProcessingOrderTest {
  6.  
  7. public static void main(String[] args) {
  8. Stream.of("d2", "a2", "b1", "b3", "c")
  9. .filter(s -> {
  10. System.out.println("filter: " + s);
  11. return true;
  12. })
  13. .forEach(s -> System.out.println("forEach: " + s));
  14.  
  15. //Reduce the processing by anyMatch instead of filter the order
  16. Stream.of("d2", "a2", "b1", "b3", "c")
  17. .map(s -> {
  18. System.out.println("map: " + s);
  19. return s.toUpperCase();
  20. })
  21. .anyMatch(s -> {
  22. System.out.println("anyMatch: " + s);
  23. return s.startsWith("A");
  24. });
  25. }
  26. }
Add Comment
Please, Sign In to add comment