File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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.
I agree. Here's the link:
subject: switch case
Similar Threads
Switch Enum Question
Comparing to a large number a strings?
SAX unable to locate DTD from XML
Just Java 2 clock class help required (Resolved)
Box or Unbox