Java first introduce the switch statement:
switch statement:
Format
switch (expression) {
Case Value 1:
statement 1;
BREAK;
Case 2 values:
sentence 2;
BREAK;
...
...
default:
statement n + 1;
BREAK;
}
Implementation process:
- switch expression to get a result, you first need to follow the case and compare the value 1, if the match, execute the statement 1, met break, end of statement
- If the value does not match the back of the case 1, case 2 and then matched value, if successful, execute the statement 2, the end of the break
- This in turn choose to judge, if not match, the default statement executes, the end!
the latter can now switch expression data types: int, Short, char, byte
JDK1.5 (included) after the expression can be enumerated types (enum) (Phase II ---> jdk new features) (reference types)
JDK1.7 (inclusive) after expression can be of type String
long as the expression can not switch the