I have an Enum with approximately 70 fields.
I want 10 of them to be displayed in a specific order, then I want the rest to be displayed in alphabetical order using a comparator. I tried a lot of things, but I can't get it to work.
Here is an example of a listing with reduced attributes. I want to display Picard, Worf and William first, then the rest in alphabetical order
I can not use any third libraries. It must be Java. Therefore, if you want to provide answers in guava or respond with apache, please do this in addition to the explicit kernel.
public enum StarTrek { JeanLucPicard("Picard"), GeordiLaForge("Geordi"), DiannaTroi("Dianna"), Worf("Worf"), WilliamRiker("William"), Q("Q"); private String label; StarTrek(String label) { this.label = label; } @Override public String toString() { return label; } } List<StarTrek> specificOrder = Arrays.asList(StarTrek.JeanLucPicard, StarTrek.Worf, StarTrek.WilliamRiker); Comparator<StarTrek> comp = new Comparator<StarTrek>() { @Override public int compare(StarTrek o1, StarTrek o2) {
source share