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 level; public Item(Level level) { this.level = level; } } public static void main(String[] args) { Item item1 = new Item(Level.B); Item item2 = new Item(Level.A); Item item3 = new Item(Level.D); Item item4 = new Item(Level.C); List<Item> items = new ArrayList<>(List.of(item1, item2, item3, item4)); } I want the order to be A,B,C,D
enum?