<<< The syntax of the switch statement | Index | Switch statement using a character >>> |
In Java, switch, case, break, and default are reserved words
The switchExpression (also called the selector) can of types
int, byte, short, char
enumerated types
String
Character, Byte, Short, or Integer object
In a switch statement, the switchExpression is evaluated first to determine which action statements should be selected for execution
The statements that follow the matching case value are executed
A particular case value must appear only once in the switch statement
One or more statements may follow a case label -- no need to use braces to turn multiple statements into a single compound statement
The default label is optional
<<< The syntax of the switch statement | Index | Switch statement using a character >>> |