LIKE, SHARE & SUBSCRIBE
Switch statement is a multi-branch selection statement. By using switch statement we can control the order of execution of our Java code.
Here controlling process is based on an expression, which is compared to the different case's value. These cases contain statements which get executed if the case and expression value gets matched.
We can make as many cases as we desire. That's why it is a better alternative for else-if statements. By using switch statements for the control of execution order, our code's readability gets improved.
We also include "default" case in our switch statements so that we can verify that whether our case gets executed or not. This is not mandatory, but we must include it so that we can track the execution order.
Data types allowed in switch statements.
1) byte
2) short
3) int
4) char
Wrapper classes like Byte, Short, Integer, Character & ENUMs (Enumerated Data Type) were also included in JDK 1.5 version.
String class was also included in JDK 1.7 version.
If, If-Else, Else-If Statement Condition in Java : • 26 - If, If Else, Else If Statements ...
Thanks for watching & stay tuned.
Like us on Facebook - https://goo.gl/y7oxYc
Follow us on Twitter - https://goo.gl/UKmTfn