Java Calendar getDisplayName() Method //return StringThe getDisplayName() method of java.util.Calendar class returns String representation of the calendar field value passed as parameter in a given style and local. Style and local are also passed as parameter. If no String representation is available, getDisplayName() returns null value. If String representation is available, get() method is called to access the calendar field value. SyntaxParameterfield - the calendar fields are passed like MONTH , DAY_OF_WEEK etc style - it is the style to be applied to String representation of field passed as parameter. locale - the locale for the string representation. ReturnsThe string representation of field passed as parameter in specified format (style) and local is returned. ThrowsIllegalArgumentExeption NullPointerException Example 1Output: Sunday Monday Tuesday Wednesday Thursday Friday Saturday Example 2Output: Days of week are January February March April May June July August September October November December Months of year are Sunday Monday Tuesday Wednesday Thursday Friday Saturday Example 3Output: Days of year do not have String representation null null null null null null null Java Calendar getDisplayName(int field, int style, Locale locale) MethodThe getDisplayName() method of java.util.Calendar class returns Map representation of the calendar field value passed as parameter in a given style and local. Style and local are also passed as parameter. As this method returns Map representation of passed field it has a String representation and a key value in integer form. Key value is used to uniquely identify. SyntaxParameterfield - the calendar fields are passed like MONTH , DAY_OF_WEEK etc style - it is the style to be applied to String representation of field passed as parameter. locale - the locale for the string representation. ReturnsThe Map representation of field passed as parameter in specified format (style) and local is returned. Local and style is also passed as parameter. ThrowsIllegalArgumentExeption NullPointerException Example 1Output: List of Days in a week are : {Friday=6, Monday=2, Saturday=7, Sunday=1, Thursday=5, Tuesday=3, Wednesday=4} Example 2Output: List of Months are : {April=3, August=7, December=11, February=1, January=0, July=6, June=5, March=2, May=4, November=10, October=9, September=8} Next TopicJava-calendar-getfirstdayofweek-method |