Display weekday names in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 10-Dec-2018 11:44:46
Advertisements