Answers for "sort list of objects by attribute java"

1

sort list of objects by attribute java

ArrayList<Employee> employees = getUnsortedEmployeeList();
             
Comparator<Employee> compareById = (Employee o1, Employee o2) -> o1.getId().compareTo( o2.getId() );
 
Collections.sort(employees, compareById);
 
Collections.sort(employees, compareById.reversed());
Posted by: Guest on April-24-2020

Code answers related to "sort list of objects by attribute java"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language