You can simply use sort method of list to sort the list of employees.
List<Employee> employeeList = createEmployeeList(); employeeList.sort((e1,e2)->e1.getAge()-e2.getAge()); employeeList.forEach(System.out::println);
Don't miss the next article!
Be the first to be notified when a new article or Kubernetes experiment is published.
Share This