Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
Java

switch Statement in Java

Select among many options with switch (classic and enhanced switch).

switch Statement in Java — a practical guide to Java switch with clear examples you can reuse in real projects.

Java Tutorial Series (17/90). Prefer one article? Read the complete Java tutorial.

Short description

Modern Java supports switch expressions. Always cover defaults for unexpected values.

Switch expression

int day = 3;
String name = switch (day) {
    case 1 -> "Mon";
    case 2 -> "Tue";
    case 3 -> "Wed";
    default -> "Other";
};
System.out.println(name);

Leave a reply

Your email address will not be published. Required fields are marked *