Please help me to understand how to replace lambdas with method reference for the method below.
public List<Person> sortByStartDate_ASC(LinkedHashSet<Person> personList) {
List<Person> pList = new ArrayList<Person>(personList);
Collections.sort(pList, (Person person1, Person person2) -> person1
.getStartDate().compareTo(person2.getStartDate()));
return pList;
}
The equivalent method reference would be
comparing(Person::getStartDate)
- note that in your specific case you could sort the stream directly. Also there is no point restricting your method to only acceptLinkedHashSet
s - any collection would do:Note required static imports: