How to retrieve Enum name using the id?

前端 未结 11 1657
一整个雨季
一整个雨季 2020-12-05 13:11

I have the enum as:

public enum EnumStatus {

    PASSED(40L, \"Has Passed\"),
    AVERAGE(60L, \"Has Average Marks\"),
    GOOD(80L, \"Has Good         


        
11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 13:56

    Add a method in your Enum and get it by passing ids.

     public static ArrayList getEnumStatusById(ArrayList idList) {
        ArrayList listById = new ArrayList();
        for(EnumStatus es: EnumStatus.values()) {
            if( idList.contains(es.getId())) {
                listById.add(es);
            }
        }
        return listById;
    }
    

提交回复
热议问题