Switch statement with string


Source code

1class SwitchStatementWithString {
2
3 int stringToInt(String str) {
4 int returnValue;
5 switch (str) {
6 case "one":
7 returnValue = 1;
8 break;
9 case "two":
10 case "TWO":
11 returnValue = 2;
12 break;
13 default:
14 returnValue = 100;
15 }
16 return returnValue;
17 }
18
19}

Bytecode



Java compiler version: 21
Other examples
Main page