Java Program to List Weekday Names



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
Updated on: 2020-06-27T14:46:33+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements