Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

switch on String

 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashmap?
 
Sunil Kumar
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the action is same for all the string matches then populate them in a static string list and use contains.
 
Sunil Kumar
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic