switch Statement with Strings in Java


switch can also be used with strings in Java, making it great for selecting among multiple options.

Source Code

String day = "Monday";
switch (day) {
    case "Monday":
        System.out.println("It's Monday!");
        break;
    case "Friday":
        System.out.println("It's Friday!");
        break;
    default:
        System.out.println("Looking forward to the Weekend");
        break;
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments