Enum for days of week in Java


To set enum for days of the week, set them as constants

enum Days {
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
}

Now create objects and set the above constants −

Days today = Days.Wednesday;
Days holiday = Days.Sunday;

The following is an example −

Example

 Live Demo

public class Demo {
   enum Days {
      Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
   }
   public static void main(String[] args) {
      Days today = Days.Wednesday;
      Days holiday = Days.Sunday;
      System.out.println("Today = " + today);
      System.out.println(holiday+ " is holiday");
   }
}

Output

Today = Wednesday
Sunday is holiday

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 29-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements