Java introduced the arrow syntax for switch, replacing the colon-and-break pattern with ->. This form does not fall through, so you can't forget a break.
int day = 3;
switch (day) {
case 1 -> System.out.println("Monday");
case 2 -> System.out.println("Tuesday");
case 3 -> System.out.println("Wednesday");
case 4 -> System.out.println("Thursday");
case 5 -> System.out.println("Friday");
default -> System.out.println("Weekend");
}
No break needed. Each arrow case runs its statement and stops. If you need multiple statements in one case, wrap them in a block:
case 1 -> {
System.out.println("Monday");
System.out.println("Start of the week");
}
You can also group values: case 6, 7 -> System.out.println("Weekend");. This replaces the old fall-through grouping pattern with something much easier to read.