DEV Community

Murali Rajendran
Murali Rajendran

Posted on

Switch case in Java

It is used to check some valid expression like Traffic light real world example.

SYNTAX:

String day="laundry";
switch(day)
{
case "hr":
System.out.println("hr department");
break;
case "laundry":
System.out.println("laundry department");
break;
case "laundry1":
System.out.println("laundry department");
case "front office":
System.out.println("front king department");
default:
System.out.println("hi welcome");

Top comments (1)

Collapse
 
vpospichal profile image
Vlastimil Pospíchal

Try enum with the constructor:
docs.oracle.com/javase/tutorial/ja...