Thursday, December 18, 2025
HomeLanguagesJavaCalendar getDisplayNames() Method in Java with Examples

Calendar getDisplayNames() Method in Java with Examples

The getDisplayNames(int cal_field, int cal_style, Locale local) method of Calendar class is used to return a map containing all the names of the calendar field(int cal_field) in the given style(int cal_style) and locale(Locale local) and their corresponding field values.

Syntax:

public Map getDisplayNames(int field, int style, Locale locale)

Parameters: The method takes three parameters:

  • cal_field: This is of integer type and refers to the field of the calendar on which the operation is to be performed.
  • cal_style: This is of integer type and refers to the style that is supposed to be applied to the string representation.
  • local: This is of Locale object type and refers to the locale representing the string.

Return Value: The method either returns the string representation of the given field in the form of the passing style else null if no string representation is available.

Below programs illustrate the working of getDisplayNames() Method of Calendar class:
Example:




// Java Code to illustrate
// getdisplaynames() Method
  
import java.util.*;
  
public class Calendar_Demo_Locale {
    public static void main(String args[])
    {
  
        // Creating the Calendar
        Calendar cal = Calendar.getInstance();
  
        // Creating the Locale
        Locale local = Locale.getDefault();
  
        // Calling the getdisplaynames method
        Map<String, Integer> cal_repres = cal.getDisplayNames(Calendar.DAY_OF_WEEK,
                                                              Calendar.LONG, local);
  
        NavigableMap<String, Integer> Nav_Map = new TreeMap<String, Integer>(cal_repres);
  
        // Displaying the results
        System.out.printf("The complete list is: %n%s%n", Nav_Map);
    }
}


Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#getDisplayNames(int, %20int, %20java.util.Locale)

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
108 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12035 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6910 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS