0
Can someone post an example of switch using strings and one example using characters, just to see the proper structure?
And is it possible to switch booleans? although I understand their is no point to it
3 Answers
+ 1
some code from a servlet...
String action = request.getParameter("action");
if(action != null){
switch(action)
case "a1":
//code
break;
case "a2":
//code
break;
...
...
default:
//code
break;
}
}
for char values you would use
case 'a':
...
I believe.
there is no need to switch Boolean because you could just use a ternary operator.
you should also be able to switch integers.
hope this helps
+ 1
********there are curly brackets after the switch statement.
switch (a){
...}
0
thanks a lot