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

23rd Feb 2017, 5:05 AM
George Kostopoulos
George Kostopoulos - avatar
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
23rd Feb 2017, 5:25 AM
Michael Szczepanski
Michael Szczepanski - avatar
+ 1
********there are curly brackets after the switch statement. switch (a){ ...}
23rd Feb 2017, 5:26 AM
Michael Szczepanski
Michael Szczepanski - avatar
0
thanks a lot
23rd Feb 2017, 5:35 AM
George Kostopoulos
George Kostopoulos - avatar