- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java Calendar getDisplayNames() Method
Description
The Java Calendar getDisplayNames() method returns a Map containing all names of the calendar field in the given style and locale and their corresponding field values.
Declaration
Following is the declaration for java.util.Calendar.getDisplayNames() method
public Map<String,Integer> getDisplayNames(int field,int style,Locale locale)
Parameters
field − the calendar field.
style − the style that will be applied to the string representations
locale − the string representation locale
Return Value
The method returns a Map containing all display names in style and locale and their field values, or null if no string representation is available.
Exception
IllegalArgumentException − if field or style are invalid, or if this Calendar is non-lenient and any of the fields has invalid values
NullPointerException − if locale is null
Getting Display Names of Days of Week from a Calendar Instance Example
The following example shows the usage of Java Calendar getDisplayNames() method. We're creating an instance of a Calendar of current date. Then we're creating a default locale. Using getDisplayNames(), we're getting all representations and printing
package com.tutorialspoint; import java.util.Calendar; import java.util.Locale; import java.util.Map; public class CalendarDemo { public static void main(String[] args) { // create calendar and locale Calendar now = Calendar.getInstance(); Locale locale = Locale.getDefault(); // call the getdisplaynames method Map< String, Integer> representations = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale); // print the results System.out.printf("Whole list: ", representations); } }
Output
Let us compile and run the above program, this will produce the following result −
Whole list: {Monday=2, Sunday=1, Thursday=5, Friday=6, Saturday=7, Wednesday=4, Tuesday=3}
Getting Display Names of Days of Week from a Calendar Instance for CA Locale Example
The following example shows the usage of Java Calendar getDisplayNames() method. We're creating an instance of a Calendar of current date. Then we're creating a locale for fr. Using getDisplayNames(), we're getting all representations and printing them.
package com.tutorialspoint; import java.util.Calendar; import java.util.Locale; import java.util.Map; public class CalendarDemo { public static void main(String[] args) { // create calendar and locale Calendar now = Calendar.getInstance(); Locale locale = new Locale("fr", "CA"); // call the getdisplaynames method Map< String, Integer> representations = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale); // print the results System.out.printf("Whole list: %s", representations); } }
Output
Let us compile and run the above program, this will produce the following result −
Whole list: {lundi=2, dimanche=1, vendredi=6, mercredi=4, jeudi=5, samedi=7, mardi=3}
Getting Display Names of Days of Week from a Calendar Instance for GB Locale Example
The following example shows the usage of Java Calendar getDisplayNames() method. We're creating an instance of a Calendar of current date. Then we're creating a locale for en. Using getDisplayNames(), we're getting all representations and printing them.
package com.tutorialspoint; import java.util.Calendar; import java.util.Locale; import java.util.Map; public class CalendarDemo { public static void main(String[] args) { // create calendar and locale Calendar now = Calendar.getInstance(); Locale locale = new Locale("en", "GB"); // call the getdisplaynames method Map< String, Integer> representations = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale); // print the results System.out.printf("Whole list: %s", representations); } }
Output
Let us compile and run the above program, this will produce the following result −
Whole list: {Monday=2, Sunday=1, Thursday=5, Friday=6, Saturday=7, Wednesday=4, Tuesday=3}