File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes switch on String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "switch on String" Watch "switch on String" New topic
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: 8834
    
    7

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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: switch on String
 
Similar Threads
Convert "\n" to char '\n'
is there a quicker way to read in input besides bufferedreader?
switch statement on String
switch doubt..
switch with Strings