Created
December 17, 2017 15:15
-
-
Save Jayasagar/3bf35331ce165c0c1193d6a294da5a67 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| consumerList | |
| .stream() | |
| // map intermediate operation | |
| // 'map' is used to transform one element type into other, here we transformed Consumer into String | |
| .map(Consumer::getName) | |
| // 'distinct' intermediate operation | |
| .distinct() | |
| // 'sorted' intermediate operation | |
| .sorted() | |
| // 'reduce' terminal operation | |
| // 'reduce' is used to produce single output | |
| // .reduce(String::concat); | |
| .reduce((preVName, nextName) -> preVName + " " + nextName) | |
| .ifPresent((result) -> System.out.println(result)); | |
| // Outout: Bob Malli Satti Sri | |
| // In above code you can also use 'reduce(String::concat)' | |
| // Please read Optional to understand more on ifPresent method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment