Created
November 2, 2014 21:45
-
-
Save vfarcic/2faa70951b44b21938b4 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.IntSummaryStatistics; | |
import java.util.List; | |
public class PeopleStats { | |
public static Stats getStats7(List<Person> people) { | |
long sum = 0; | |
int min = people.get(0).getAge(); | |
int max = 0; | |
for (Person person : people) { | |
int age = person.getAge(); | |
sum += age; | |
min = Math.min(min, age); | |
max = Math.max(max, age); | |
} | |
return new Stats(people.size(), sum, min, max); | |
} | |
public static IntSummaryStatistics getStats(List<Person> people) { | |
return people.stream() | |
.mapToInt(Person::getAge) | |
.summaryStatistics(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment