Created
November 2, 2014 21:40
-
-
Save vfarcic/eb9356135742781c39ba 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
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks