switch expression
A switch that produces a value, so it can be stored or printed.
A switch used as an expression (Stable since Java 14): each case supplies a value after -> or with yield, and the switch must be exhaustive.
Examples
int days = switch (month) { case 2 -> 28; case 4, 6, 9, 11 -> 30; default -> 31; };
See also