티스토리 뷰

공부

[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);

 

[출처] 

https://howtodoinjava.com/sort/collections-sort/

https://stackoverflow.com/questions/33487063/java-8-sort-list-of-objects-by-attribute-without-custom-comparator

https://stackoverflow.com/questions/28607191/how-to-use-a-java8-lambda-to-sort-a-stream-in-reverse-order

728x90

'공부' 카테고리의 다른 글

[nginx] configure  (0) 2019.07.28
[UTF-8] 인코딩 BOM(Byte Order Mark)  (0) 2019.07.28
Easy way to convert Iterable to Collection  (0) 2019.07.28
No bean named 'transactionManager' available  (0) 2019.07.28
[Spark] Delete Hbase by Spark  (0) 2019.07.28
댓글