Core Java: A traditional switch falls through without break, an arrow switch doesn't

A classic switch statement runs every case from the matched label onward until a break, while a switch using arrow labels executes only the matched branch.

Code
int day = 3;
StringBuilder oldStyle = new StringBuilder();
switch (day) {
    case 1:
    case 2:
    case 3:
        oldStyle.append("weekday-ish ");
    case 4:
        oldStyle.append("falls-through");
        break;
    default:
        oldStyle.append("other");
}
String arrowResult = switch (day) {
    case 1, 2, 3 -> "weekday-ish";
    case 4 -> "thursday";
    default -> "other";
};
System.out.println("Old style: " + oldStyle);
System.out.println("Arrow style: " + arrowResult);
Output
Old style: weekday-ish falls-through
Arrow style: weekday-ish
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-27

© Java Coding Hub · About · Contact · Privacy · Terms