How has switch expressions changed in recent Java versions?

Java, switch expressions, Java 12, Java 14, enhanced switch
Switch expressions in Java have evolved significantly in recent versions, providing a more concise and flexible way to handle multiple conditions in your code.
          // Example of switch expression introduced in Java 12
          String day = "MONDAY";
          String typeOfDay = switch (day) {
              case "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY" -> "Weekday";
              case "SATURDAY", "SUNDAY" -> "Weekend";
              default -> throw new IllegalArgumentException("Invalid day: " + day);
          };

          System.out.println(typeOfDay); // Output: Weekday
        

Java switch expressions Java 12 Java 14 enhanced switch