Pattern Matching for Switch

Available in preview from Java 17

Ensure your SDK and Language Level are at least Java 17 (Preview) in your Project Structure with ⌘; (macOS), or Ctrl+Alt+Shift+S (Windows/Linux).

IntelliJ IDEA highlights code that can be replaced with a switch expression using pattern variables. Press ⌥⏎ (macOS) or Alt+Enter (Windows/Linux) and choose "Replace if with switch".