Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Created November 2, 2014 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vfarcic/2faa70951b44b21938b4 to your computer and use it in GitHub Desktop.
Save vfarcic/2faa70951b44b21938b4 to your computer and use it in GitHub Desktop.
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