Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Created November 2, 2014 21:40
Show Gist options
  • Save vfarcic/eb9356135742781c39ba to your computer and use it in GitHub Desktop.
Save vfarcic/eb9356135742781c39ba to your computer and use it in GitHub Desktop.
package com.technologyconversations.java8exercises.streams;
import java.util.List;
public class Sum {
public static int calculate7(List<Integer> numbers) {
int total = 0;
for (int number : numbers) {
total += number;
}
return total;
}
public static int calculate(List<Integer> people) {
return people.stream() // Convert collection to Stream
.reduce(0, (total, number) -> total + number); // Sum elements with 0 as starting value
}
}
@nsriramya
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment