We have an enum
enum listE {
LE1,
LE4,
LE2,
LE3
}
Furthermore, we have a list that contains the strings ["LE1","LE2","LE3","LE4"]. Is there a way to sort the list based on the enum defined order (not the natural String order).
The sorted list should be ["LE1", "LE4", "LE2", "LE3"].
Enum<E>implementsComparable<E>via the natural order of the enum (the order in which the values are declared). If you just create a list of the enum values (instead of strings) via parsing, then sort that list usingCollections.sort, it should sort the way you want. If you need a list of strings again, you can just convert back by callingname()on each element.