This has already been mentioned, but here is a way to place the code within a method:
public static String getMonthName(int monthIndex) {
return new DateFormatSymbols().getMonths()[monthIndex].toString();
}
or if you wanted to create a better error than an ArrayIndexOutOfBoundsException:
public static String getMonthName(int monthIndex) {
//since this is zero based, 11 = December
if (monthIndex < 0 || monthIndex > 11 ) {
throw new IllegalArgumentException(monthIndex + " is not a valid month index.");
}
return new DateFormatSymbols().getMonths()[monthIndex].toString();
}