티스토리 뷰

공부

[java] sort with Comparator

승가비 2024. 4. 2. 23:43
728x90
items.sort(Comparator.comparing(item -> item.level.name()));

https://stackoverflow.com/questions/68211158/how-to-sort-a-list-of-objects-by-an-enum-field

 

How to sort a list of objects by an enum field?

I have a list of objects that contains an enum field. How can I sort it by the enum values alphabetically? For example, static enum Level { D, C, A, B } static class Item { Level

stackoverflow.com

 

728x90
댓글