• Post Reply Bookmark Topic Watch Topic
  • New Topic

Switch-statement and Strings  RSS feed

 
Kristian Ledung
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use a switch-statement where the expression to evaluate against is a String. How can I do that, when the switch-statement only allows Integer or literals as expressions?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use if-else instead.
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe in java 5 you would be able to do this using an Enum. I have not tried it myself, but I do seem to remember reading about it in the Features descriptions for Java 5.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin,
maybe you're talking about this:
http://www.jcp.org/aboutJava/communityprocess/jsr/tiger/enum.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!