Facebook
From Paltry Armadillo, 3 Weeks ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 29
  1. private double calculateAvg(final String nationality, final List<Person> people) {
  2.         if(Objects.isNull(nationality) || Objects.isNull(people)) {
  3.             return 0;
  4.         }
  5.        
  6.         return people.stream()
  7.                 .filter(person -> Objects.nonNull(person.getNationality()) && person.getNationality().equals(nationality))
  8.                 .mapToInt(Person::getAge)
  9.                 .average()
  10.                 .orElse(0);
  11.     }