Enter enum (enumeration) Code to get an ENUM description

tags: Java technology sharing  java  rear end  enum

// Create a new one
public enum StatusEnum {
    two_enum(200,"success","success"),
    five_hundred_enum(500,"error","fail");
    private Integer code;
    private String type;
    private String desc;

    StatusEnum(Integer code, String type, String desc) {
        this.code = code;
        this.type = type;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    /**
           * Enter Code to get the corresponding DESC
     * @param code
     * @return
     */
    public static String getDesc(Integer code) {
        StatusEnum[] resultEnums = StatusEnum.values();
        for (StatusEnum statusEnum : resultEnums) {
            if (statusEnum.code.equals(code)) {
                return statusEnum.desc;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(getDesc(200));
    }
}

The result of running is

Best Regards!
Make a little progress every day!

Intelligent Recommendation

Enum enumeration to get the message three methods through code

In the development encountered Enum's code to get the message, so a variety of Baidu, find a 3 method The first lowest method, not recommended Add a getPaymentType method to the enumerated class, whic...

Enum (enumeration)

Creating an enum type uses the enum keyword, implying that the type created is a subclass of the java.lang.Enum class (java.lang.Enum is an abstract class). Each value of the enumerated type will be m...

Enumeration Enum

What is enumeration? Why enumerate? Enumerations how to use? Pros VS Cons   1. What is an enumeration First, we decompile file from an enumeration class to understand what enum class    ...

Enumeration -enum

  ...

More Recommendation

Enumeration (Enum)

Enum type is defined by the programmer, or the same as the class structure. ● structure as enumerated value type, so their data is stored directly, rather than storing data and separated into a refere...

【Enumeration enum】

operation result:  ...

Enumeration: enum

The so-called enumeration is to realize the specified value range, and all content is obtained from the specified range. Enumeration was introduced after Java 1.5, and the keyword enum was used to dir...

Sword refers to the 15th question of OFFER (binary solution)

topic Enter a number, this number is determined corresponding to 32-bit binary number 1 is contained, and returns the number of answer Solution ideas First of all, I want to explain that this 1 <&l...

Thread operation 02_pthread lock operation

table of Contents mutex definition function pthread_mutex_init function pthread_mutex_destroy function pthread_mutex_lock function pthread_mutex_unlock function pthread_mutex_trylock function Read-wri...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top