I have a list of listings of all states in the USA, as shown below:
public enum State { AL, AK, AZ, AR, ..., WY }
and in my test file I read the input from a text file that contains the state. Since they are strings, how can I compare them with the value of an enumeration list in order to assign a value to a variable that I set as:
private State state;
I understand that I need to list a list of listings. However, since values ββare not string types, how can you compare it? This is what I just type blindly. I donβt know if it is right or wrong.
public void setState(String s) { for (State st : State.values()) { if (s == State.values().toString()) { s = State.valueOf(); break; } } }
java string enums compare
Maximus seng
source share