I wanna programmatically convert an integer in the range 1-12 to corresponding month name. (e.g. 1 -> January, 2 -> February) etc using Java Calendar class in one statement.
Note : I want to do it using Java Calendar class only. Don’t suggest any switch-case or string array solution.
Thanks.
The
Calendarclass is not the best class to use when it comes obtaining the localized month name in one statement.The following is an example of obtaining the month name of a desired month specified by a
intvalue (where January is 1), using only theCalendarclass:The above code will return the month name in the system locale.
If another locale is required, one can specify another
Localeby replacing theLocale.getDefault()with a specific locale such asLocale.US.