I have an enum list of all the states in the US as following:
public enum State
{ AL, AK, AZ, AR, ..., WY }
and in my test file, I will rea
Use .name()
method. Like st.name()
. e.g. State.AL.name()
returns string "AL".
So,
if(st.name().equalsIgnoreCase(s)) {
should work.
try this
public void setState(String s){
state = State.valueOf(s);
}
You might want to handle the IllegalArgumentException that may be thrown if "s" value doesn't match any "State"
to compare enum to string
for (Object s : State.values())
{
if (theString.equals(s.toString()))
{
// theString is equal State object
}
}