Java Program to list Weekday names

Java 8Object Oriented ProgrammingProgramming

To list weekday names, use the getWeekdays () from the DateFormatSymbols class in Java.

DateFormatSymbols is a class for encapsulating localizable date-time formatting data.

Get weekday month names in an array −

String[] days = new DateFormatSymbols().getWeekdays ();

Display the weekdays −

for (int i = 0; i < days.length; i++) {
   String weekday = days[i];
   System.out.println(weekday);
}

The following is an example −

Example

 Live Demo

import java.text.DateFormatSymbols;
public class Demo {
   public static void main(String[] args) {
      String[] days = new DateFormatSymbols().getWeekdays();
      for (int i = 0; i < days.length; i++) {
         String weekday = days[i];
         System.out.println(weekday);
      }
   }
}

Output

Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
raja
Published on 27-Dec-2018 10:52:27
Advertisements