Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

switch case

 
Manoj Zachariah
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i use string values in a switch statement
ex:

 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Manoj,
no, u cannot use string values in switch() construct coz the rule for
switch() is tht the variable u pass as argument to switch() must be compatible to int i.e. only byte, char, short and int should be passed as argument to switch() and long, float , double and any object reference should not be passed.

vineela
 
Maarten Vergouwen
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you _can_ use a char, so in your example you could test for 'A', only you'd use single iso double quotes.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!