Switch method but using Strings

Hi all,

was wondering if there was a string version of the switch method where instead of requiring an int it asks for a string. I got a project which at the moment uses a lot o ifs and i wanted a better method instead. Any help?

The switch method where you have

switch (score)

{

case 0: AllGamesPlayed = AllGamesPlayed +1; break;

case 1: YLossPts = YLossPts +1; break;

case 2: YWinPts = YWinPts +1; break;

}

theres an example of a switch using an int number so depending on what score is equal will select the case is there a string version of this so i could have a switch which could select a case with a string name like yellow or green if so how?

[715 byte] By [Harbir24_7a] at [2007-10-2 10:50:04]
# 1
You can either map the String values to Integersor you can use reflection.
tschodta at 2007-7-13 3:07:45 > top of Java-index,Other Topics,Algorithms...
# 2
Reflection? Is there another way to over come using lots of IFs i was thinking about using a string but instead of trying to return the string i would get the length of the string and use that as the case instead.
Harbir24_7a at 2007-7-13 3:07:45 > top of Java-index,Other Topics,Algorithms...
# 3
> You can either map the String values to Integers> or you can use reflection.... or map those String values to little objects, say Runnables, that performwhatever they have to do when they're selected from the map.kind regards,Jos
JosAHa at 2007-7-13 3:07:45 > top of Java-index,Other Topics,Algorithms...