This Java example shows how to use enums in switch-case statement with an example in Java.
public class EnumInSwitchStatement {
public static void main(String[] args) {
System.out.println(enumInSwitch(Days.SUNDAY));
}
enum Days {
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY;
}
public static String enumInSwitch(Days day) {
switch (day) {
case SUNDAY:
return "Its Sunday!!";
case MONDAY:
return "Its Monday";
case TUESDAY:
return "Its Tuesday";
case WEDNESDAY:
return "Its Wednesday";
default:
return "Rest of the week....";
}
}
}
Output:
Its Sunday!!
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course