DayOfWeek getDisplayName() method in Java with Examples

The getDisplayName() method of java.time.DayOfWeek is an in-built function in Java which returns the textual representation of the day-of-week according to the specified Locale class parameter and TextStyle. The TextStyle defines three elements ‘FULL’, ‘SHORT’ and ‘NARROW’. Locale class represents a specific language and region of the world.
Method Declaration:
public String getDisplayName(TextStyle style, Locale locale)
Syntax:
String text = dayOfWeekObject.getDisplayName(TextStyle style, Locale locale)
Parameters: This method takes two parameters:
Return Value: The function returns returns the textual representation of the day-of-week according to the specified Locale class parameter and TextStyle.
Below programs illustrate the above method:
Program 1:
// Java Program Demonstrate getDisplayName()// method of DayOfWeek  import java.time.*;import java.time.format.TextStyle;import java.util.Locale;  class DayOfWeekExample {    public static void main(String[] args)    {        // Initializing a DayOfWeek instance        DayOfWeek dayOfWeek = DayOfWeek.MONDAY;          // Get textual representation of the        // day-of-week in FULL style        String full_name            = dayOfWeek                  .getDisplayName(TextStyle.FULL,                                  Locale.getDefault());          // Get textual representation of the        // day-of-week in SHORT style        String short_name            = dayOfWeek                  .getDisplayName(TextStyle.SHORT,                                  Locale.getDefault());          // Get textual representation of the        // day-of-week in NARROW style        String narrow_name            = dayOfWeek                  .getDisplayName(TextStyle.NARROW,                                  Locale.getDefault());          // Printing the textual names of the day-of-week        System.out.println(full_name);          System.out.println(short_name);          System.out.println(narrow_name);    }} | 
Output:
Monday Mon M
Program 2:
// Java Program Demonstrate getDisplayName()// method of DayOfWeek  import java.time.*;import java.time.DayOfWeek;import java.time.format.TextStyle;import java.util.Locale;  class DayOfWeekExample {    public static void main(String[] args)    {        // Initializing a DayOfWeek instance        DayOfWeek dayOfWeek = DayOfWeek.WEDNESDAY;          // Get textual representation of the        // day-of-week in FULL style        String full_name            = dayOfWeek                  .getDisplayName(TextStyle.FULL,                                  Locale.getDefault());          // Get textual representation of the        // day-of-week in SHORT style        String short_name            = dayOfWeek                  .getDisplayName(TextStyle.SHORT,                                  Locale.getDefault());          // Get textual representation of the        // day-of-week in NARROW style        String narrow_name            = dayOfWeek                  .getDisplayName(TextStyle.NARROW,                                  Locale.getDefault());          // Printing the textual names of the day-of-week        System.out.println(full_name);          System.out.println(short_name);          System.out.println(narrow_name);    }} | 
Output:
Wednesday Wed W
				
					


