Last active
December 18, 2016 13:03
-
-
Save ru-rocker/642975f6afd701d0e3cdedfebb4fd4fc to your computer and use it in GitHub Desktop.
Sample usage of reduce operation in Java Stream API with two parameters
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
//append all model into single line of string with default model: Renault | |
String carModels = cars.stream() | |
.map(c1 -> c1.getModel()) | |
.distinct() | |
.reduce("Renault", (s1, s2) -> s1 + "|" + s2); | |
System.out.println(carModels); | |
//Output: Renault|BMW|Ford|Toyota |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment