Java 14: Switch expressions with arrow labels

Switch can be an expression that returns a value, with no fall-through.

Code
int day = 6;
String kind = switch (day) {
    case 1, 2, 3, 4, 5 -> "weekday";
    case 6, 7 -> "weekend";
    default -> "invalid";
};
System.out.println(kind);
Output
weekend
Advertisement

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-07-26