Skip to content

Instantly share code, notes, and snippets.

@ru-rocker
Last active December 18, 2016 13:03
Show Gist options
  • Save ru-rocker/642975f6afd701d0e3cdedfebb4fd4fc to your computer and use it in GitHub Desktop.
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
//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