Skip to content

Commit

Permalink
simplified to use method toList instead of collector(Collectors...)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorovychh committed Oct 26, 2023
1 parent 42d0db8 commit b3faaa7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/practice/StreamPractice.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public List<Person> selectMenByAge(List<Person> peopleList, int fromAge, int toA
.filter(person -> person.getSex().equals(Person.Sex.MAN)
&& fromAge <= person.getAge()
&& toAge >= person.getAge())
.collect(Collectors.toList());
.toList();
}

public List<Person> getWorkablePeople(int fromAge, int femaleToAge,
Expand All @@ -57,15 +57,15 @@ public List<Person> getWorkablePeople(int fromAge, int femaleToAge,
|| (person.getSex().equals(Person.Sex.MAN) && maleToAge >= person.getAge()));
return peopleList.stream()
.filter(workableFilter)
.collect(Collectors.toList());
.toList();
}

public List<String> getCatsNames(List<Person> peopleList, int femaleAge) {
return peopleList.stream()
.filter(person -> person.getSex().equals(Person.Sex.WOMAN)
&& person.getAge() >= femaleAge)
.flatMap(person -> person.getCats().stream().map(Cat::getName))
.collect(Collectors.toList());
.toList();
}

public List<String> validateCandidates(List<Candidate> candidates) {
Expand Down

0 comments on commit b3faaa7

Please sign in to comment.