I am practicing with Java 8. I don't understand why this method always return 0, or better the identity value:
public static Integer getMinAge(List<Person> peopleList) {
return peopleList.stream().mapToInt(Person::getAge).reduce(0, Integer::min);
}
Surprisingly, the Integer::max method returns the correct value. What am I doing wrong here?
reduce(Integer.MAX_VALUE, Integer::min).reduce(Integer::min)or even.min()instead, but those methods return an OptionalInt - because without the provided identity value, there may be no result (if the stream is empty!)