From the course: Java 11+ Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Evaluate conditions with switch-case

Evaluate conditions with switch-case - Java Tutorial

From the course: Java 11+ Essential Training

Start my 1-month free trial

Evaluate conditions with switch-case

- [Instructor] The if and else keywords give you complete flexibility in writing conditional code, but you can sometimes write that code more efficiently using the switch statement. A switch statement examines a single expression and then compares it to multiple possible values. You control the flow of execution based on when the values match. In my starting code, I'm getting the current month as a numeric value, from the current system, and I'll add a switch keyword. When I select switch and let it auto complete, IntelliJ IDEA adds a pair of parenthesis. Add an expression inside the pair of parenthesis that you want to evaluate. This can be a primitive value such as number, or can be a string. I'll evaluate the current month number. Now I'm going to press a keyboard shortcut that only works in IntelliJ IDEA, on Mac it's command shift return, and on windows it's control shift enter, and that auto completes the…

Contents