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

switch case

Manoj Zachariah
Ranch Hand

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

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.

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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: switch case
It's not a secret anymore!