Skip to content

Instantly share code, notes, and snippets.

@rastadrian
Created May 12, 2017 03:09
Show Gist options
  • Select an option

  • Save rastadrian/f59475a67e8decef277dab6bfe185d79 to your computer and use it in GitHub Desktop.

Select an option

Save rastadrian/f59475a67e8decef277dab6bfe185d79 to your computer and use it in GitHub Desktop.
private int withoutStreams() {
int[] values = {1, 2, 3, 4, 5, 6, 7, 8};
int sum = 0;
for (int value : values) {
if (value > 3) {
sum += value;
}
}
return sum;
}
private int withStreams() {
int[] values = {1, 2, 3, 4, 5, 6, 7, 8};
return Arrays.stream(values)
.filter(value -> value > 3)
.sum();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment