Syntax error Display weekday names in Java

Display weekday names in Java



To display weekday names in Java, use the getWeekdays() method.

For that, firstly import the following package.

import java.text.DateFormatSymbols;

Now, create a string array and get all the weekday names using the getWeekdays() method.

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

Example

 Live Demo

import java.text.DateFormatSymbols;
public class Demo {
   public static void main(String[] args) {
      String[] weekDays = new DateFormatSymbols().getWeekdays();
      System.out.println("Weekday names...");
      for(String days: weekDays){
      System.out.println(days);
   }
}
}

Output

Weekday names...

Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Updated on: 2020-06-26T08:34:35+05:30

483 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements