Switch Statements & Expressions in Java
🟢 Beginner
📖 Definition
Java 14+ Switch Expressions use arrow syntax (case X ->) to prevent fallthrough and return values.
âš¡ Code Example
public class SwitchDemo {
public static void main(String[] args) {
String day = "MON";
String res = switch (day) {
case "MON", "TUE" -> "Weekday";
default -> "Weekend";
};
System.out.println(res);
}
}
🧠Navigation
← 03. Else-If Ladder in Java | Module Index | 05. Nested Conditionals in Java →