Stewart Clay Stewart Clay - 7 months ago 37
Java Question

Is this way of searching an enum acceptable

i am busy with enum's and was looking at a way to search an enum to see if a string a user enters is there, so i created this.


try {
String A = "DECc";
} catch(Exception e) {
System.out.println("Could not find an enum with the String you entered");


yes this is good.. the other option is "to string" all the enum elements and compare the string to them one by one:

for (Month m : Month.values()) {
    if ( {

but your way is really better...