공부
[Java] CollectionsUtils.sort
승가비
2019. 7. 28. 18:45
728x90
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());
Arrays.stream("a", "b", "c")
.sorted()
.collect(Collectors.toList());
Arrays.stream("a", "b", "c")
.sorted(Comparator.reverseOrder()))
.collect(Collectors.toList());
Arrays.stream("a", "b", "c")
.sorted(Comparator.reverseOrder()))
.findFirst()
.orElse(null);
[출처]
728x90