
- 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.util.Calendar.getDisplayNames() Method
Description
The java.util.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
Example
The following example shows the usage of java.util.calendar.getDisplayNames() method.
package com.tutorialspoint; import java.util.*; 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); NavigableMap< String, Integer> navMap = new TreeMap< String, Integer>(representations); // print the results System.out.printf("Whole list:%n%s%n", navMap); } }
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}