Mon Dec 20 2021 12:45:44 GMT+0000 (UTC)

Saved by @lilith #java #enum

public enum FamilyMemberTypes {

    CHILD("CHILD", "Child"),
    FTH("FTH", "Father"),
    MTH("MTH", "Mother"),
    MGRMTH("MGRMTH", "Maternal Grandmother"),
    PGRMTH("PGRMTH", "Paternal Grandmother"),
    MGRFTH("MGRFTH", "Maternal Grandfather"),
    PGRFTH("PGRFTH", "Paternal Grandfather");

    private final String key;
    private final String value;

    FamilyMemberTypes(String key, String value) {
        this.key = key;
        this.value = value;

    public String getKey() {
        return key;

    public String getValue() {
        return value;

    //Lookup table
    private static final Map<String, String> lookup = new HashMap<>();

    //Populate the lookup table on loading time
    static {
        for (FamilyMemberTypes familyMemberTypes : FamilyMemberTypes.values()) {
            lookup.put(familyMemberTypes.getKey(), familyMemberTypes.getValue());

    //This method can be used for reverse lookup purpose
    public static String getValue(String key) {
        return lookup.get(key);


How to declare enum