import java.util.ArrayList;
import java.util.List;
public class IntStreamTest1 {
public static void main(String[] args) {
List<Person> people = new ArrayList<>();
people.add(new Person("Alice", 30));
people.add(new Person("Bob", 19));
people.add(new Person("Ronald", 40));
people.add(new Person("Jimi", 27));
people.add(new Person("Suzan", 60));
people.add(new Person("Jeff", 80));
people.add(new Person("Maria", 52));
// min
int min = people.stream().mapToInt(p -> p.getAge()).min().orElse(0);
System.out.println(min);
// 19
// max
int max = people.stream().mapToInt(p -> p.getAge()).max().orElse(0);
System.out.println(max);
// 80
// sum
int sum = people.stream().mapToInt(p -> p.getAge()).sum();
System.out.println(sum);
// 308
// average
double ave = people.stream().mapToInt(p -> p.getAge()).average().orElse(0.0);
System.out.println(ave);
// 44.0
}
}
class Person {
private String name;
private Integer age;
public Person(String name, Integer age) {
this.name = name;
this.age = age;
}
public Integer getAge() {
return age;
}
public String getName() {
return name;
}
public String toString() {
return "name:" + name + " age:" + age;
}
}