| Author |
switch on String
|
vitesse wei
Ranch Hand
Joined: Sep 07, 2007
Posts: 100
|
|
|
Hi,I have two string variables,they could have 20x5 combinations,how can i implement the code to check on specific combination,"if else" is not good design,I can not use "switch" on string,"enum" is not good too,what is the better solution for this?
|
SCJP 5.0<br />SCWCD1.4<br />SCBCD5
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8265
|
|
|
Hashmap?
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
Sunil Kumar
Ranch Hand
Joined: Apr 24, 2007
Posts: 76
|
|
|
If the action is same for all the string matches then populate them in a static string list and use contains.
|
Sunil Kumar
http://goodtoknowit.blogspot.com/
|
 |
Sunil Kumar
Ranch Hand
Joined: Apr 24, 2007
Posts: 76
|
|
If the actions are different use a hashmap to define the actions for each type of match Note : These are just opinions, others may vary [ December 29, 2008: Message edited by: Sunil Kumar ]
|
 |
 |
|
|
subject: switch on String
|
|
|