jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes switch case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "switch case" Watch "switch case" New topic
Author

switch case

Manoj Zachariah
Ranch Hand

Joined: Dec 08, 2003
Posts: 65
can i use string values in a switch statement
ex:

Vineela Devi
Ranch Hand

Joined: Dec 20, 2003
Posts: 191
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

Joined: Jan 12, 2004
Posts: 60
Note that you _can_ use a char, so in your example you could test for 'A', only you'd use single iso double quotes.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: switch case
 
Similar Threads
Box or Unbox
Comparing to a large number a strings?
Just Java 2 clock class help required (Resolved)
Switch Enum Question
SAX unable to locate DTD from XML