Tuesday, June 9, 2026
HomeLanguagesJavaDateFormatSymbols setWeekdays() Method in Java with Examples

DateFormatSymbols setWeekdays() Method in Java with Examples

The setWeekdays(String[] newWeekds) Method of DateFormatSymbols class in Java is used to set the names of the weekdays of the calendar in string format into some different strings. For eg., “Sunday” can be changed to “FRIDAY”, “Monday” can be changed to “WEDNESDAY” or into some other random strings.
 

Syntax:  

public void setWeekdays(String[] newWeekds)

Parameters: The method takes one parameter newWeekds which is an array of String type and refers to the new strings that are to be replaced in the existing weekdays.
Return Values: The method returns the modified names of the weekdays in a string format.
Below programs illustrate the use of setWeekdays() method. 
Example 1: 

Java




// Java code to demonstrate setWeekdays()
 
import java.text.DateFormatSymbols;
import java.util.Locale;
 
public class DateFormat_Main {
    public static void main(String args[])
    {
 
        // Initialising DateFormatSymbols object
        DateFormatSymbols format
            = new DateFormatSymbols(
                new Locale("en", "US"));
 
        // Taking the default short weekdays
        String[] Days = format.getWeekdays();
 
        // Displaying the original
        System.out.print("Original: ");
        for (int i = 1; i < Days.length; i++) {
            System.out.print(Days[i] + "  ");
        }
        System.out.println();
 
        // Taking an alternative names with
        // additional random strings
        String[] modDays = { "WEDNESDAY", "THURSDAY",
                             "FRIDAY", "MONDAY",
                             "TUESDAY", "SUNDAY",
                             "SATURDAY" };
 
        // Setting the default into modified
        format.setWeekdays(modDays);
 
        // Displaying the modified string
        String[] modifiedDays = format.getWeekdays();
 
        System.out.print("Modified: ");
        for (int i = 0; i < modifiedDays.length; i++) {
            System.out.print(modifiedDays[i] + "  ");
        }
    }
}


Output: 

Original: Sunday  Monday  Tuesday  Wednesday  Thursday  Friday  Saturday  
Modified: WEDNESDAY  THURSDAY  FRIDAY  MONDAY  TUESDAY  SUNDAY  SATURDAY

 

Example 2: 

Java




// Java code to demonstrate setShortWeekdays()
 
import java.text.DateFormatSymbols;
import java.util.Locale;
 
public class DateFormat_Main {
    public static void main(String args[])
    {
        // Initialising DateFormatSymbols object
        DateFormatSymbols format
            = new DateFormatSymbols(
                new Locale("en", "US"));
 
        // Taking the default short weekdays
        String[] Days = format.getWeekdays();
 
        // Displaying the original
        System.out.print("Original: ");
        for (int i = 1; i < Days.length; i++) {
            System.out.print(Days[i] + "  ");
        }
        System.out.println();
 
        // Taking an alternative names with
        // additional random strings
        String[] modDays = { "WEEK", "RANDOM",
                             "WEDNESDAY", "THURSDAY",
                             "FRIDAY", "MONDAY",
                             "TUESDAY", "SUNDAY",
                             "SATURDAY" };
 
        // Setting the default into modified
        format.setWeekdays(modDays);
 
        // Displaying the modified string
        String[] modifiedDays = format.getWeekdays();
 
        System.out.print("Modified: ");
        for (int i = 0; i < modifiedDays.length; i++) {
            System.out.print(modifiedDays[i] + "  ");
        }
    }
}


Output: 

Original: Sunday  Monday  Tuesday  Wednesday  Thursday  Friday  Saturday  
Modified: WEEK  RANDOM  WEDNESDAY  THURSDAY  FRIDAY  MONDAY  TUESDAY  SUNDAY  SATURDAY

 

Reference: https://docs.oracle.com/javase/8/docs/api/java/text/DateFormatSymbols.html#setWeekdays-java.lang.String:A-

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS