List<Person> persons = ...;
persons.stream().filter(p -> {
if (p.getGender() == Gender.MALE) {
return true;
}
LocalDate now = LocalDate.now();
Duration age = Duration.between(p.getBirthDate(), now);
Duration adult = Duration.of(18, ChronoUnit.YEARS);
return age.compareTo(adult) > 0) {
return true;
}
return false;
}).map(p -> p.getFirstName() + " " + p.getLastName())
.collect(Collectors.toList());
|