Answers for "sort objects in arraylist by propery"

2

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
1

sort an arraylist of objects in java

Database.arrayList.sort(Comparator.comparing(MyObject::getStartDate));
Posted by: Guest on September-09-2021

Code answers related to "sort objects in arraylist by propery"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language