I have an enum:
public static enum States {
SEL("Selangor"),
WP("Wilayah Persekutuan"),
KEL("Kelantan"),
LAB("Labuan"),
PER("Perlis");
private String value;
States(String val) {
this.value = val ;
}
public String getValue() {
return value;
}
}
The values are displayed on a Thymeleaf template by:
<div class="col-xs-6 padding-sides-none">
<div class="form-group col-xs-12 padding-sides-none">
<label class="col-xs-2 padding-sides-none" style="margin-left:15px">State</label>
<div class="col-xs-7 padding-sides-none">
<select class="form-control selectpicker" data-live-search="true"
style="width:300px;margin-left: 50px;">
<option value="" selected disabled hidden>Please select a state</option>
<option th:each="state : ${T(com.workspez.model.Accountant.States).values()}"
th:value="${state}" th:text="${state.getValue()}">
</option>
</select>
</div>
</div>
</div>
I would like to display the values in alphabetical order. is it possible? One way is to manually arrange the enum but is there any way to sort the enum list? Thanks.