How to Check Enum is Valid for given input
In many cases before using enum in our coding we need to check when the given value is member of the group or not. Here this Java will help to check the given valid is available in the enum or not.
public enum Factors {
YES("Yes"),
NO("No");
private static final Map<String, Factors> lookup = new HashMap<String, Factors>();
private final String factorStatus;
Factors(String factorStatus) {
this.factorStatus = factorStatus;
lookup.put(fruitname, Fruit);
}
public String factorStatus() {return this.factorStatus;}
public static Factors fromFactor(String factorStatus) {
return lookup.get(factorStatus);
}
}