switch expressions

The modern switch expression returns a value with arrow cases ->, with no break and no fall-through to the next case. It accepts several labels per case and must be exhaustive. The classic switch statement, with : and break, falls through to the next case if you forget break.

Example

String libelle = switch (jour) {
    case 6, 7 -> "Weekend";
    default -> "Weekday";
};

Related concepts

The whole glossary