Java switch-case statement1 min read

A switch statement allows a variable to be tested for equality against multiple values. It provides the case for the different blocks of code to be executed.

Switch expression and case value must be of the same type. There must be at least one case or multiple cases with unique case values. In the end, it can have a default case which is optional that is executed if no cases are matched.
It can also have an optional break that is useful to exit the switch otherwise it continues to the next case.

switch statement

Syntax of switch statements:

Example of a switch-case statement in Java:

Output switch-case statement:

Decision Making in java.
if statement.
if…else statement.
nested if statement.
if-else-if ladder.