Possible Duplicate:
Switch Statement With Strings in Java?
Does the “switch” statement in Java only work with integers ?
Can’t I write something like this instead ?
switch(string)
case “hello”: …
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This answer is only valid for Java 6 or earlier! Switching on strings has been added in Java 7
14.11 The switch Statement
Usually, when you need to switch on a string value, you can often work around this limitation by using char (as the string is only ever going to be one character long) or an enum. In your case, enum looks more likely.