When you compare one variable against many possible values, a long else if chain gets messy. A switch statement handles this more cleanly.
int day = 3;
switch (day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
default:
System.out.println("Other day");
}
Java evaluates the expression in parentheses, then jumps to the matching case label. The default block runs when no case matches, similar to the final else.
Each case value must be a compile-time constant. You cannot use variables or method calls as case labels.