Note: The below understanding is a collection from numerous articles which have been browsed thru the web to get the understanding.
References will be provided at the end.
SWITCH CASE:
Since JavaSE7 onwards this is one statement which works with the following data-types-
This also works with following wrapper classes-References will be provided at the end.
SWITCH CASE:
Since JavaSE7 onwards this is one statement which works with the following data-types-
- byte
- short
- int
- char
- enum types
- Byte
- Short
- Integer
- Character
- default statement is optional.
- default statement can be at the beginning and before case statements
- break statements are useful and recommended. If these are not used then next statements can get executed.
- presence of default statement helps to handle conditions at run-time, which otherwise can return unexpected results.
- One can use loops, if-then-else statements within case/default.
- Multiple case statements can be clubbed together and one result generated.
- In case this is enclosed in a for, do-while or while loop, then a break followed by loop name can break the loop;