Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

empty array position getting months

Is this a jdk/jre bug? I reported this when jdk7 was released but never received a feedback, is it normal get an array of 13 positions?

String[] months = DateFormatSymbols.getInstance().getMonths();
System.out.println(months.length + " " + Arrays.toString(months));

output: 13 [enero, febrero, marzo, abril, mayo, junio, julio, agosto, septiembre, octubre, noviembre, diciembre, ]

like image 509
FiruzzZ Avatar asked Feb 20 '26 15:02

FiruzzZ


1 Answers

Not a bug. Looking at the javadoc of the source code ( java.text.DateFormatSymbols), it says:

Month strings. For example: "January", "February", etc. An array of 13 strings (some calendars have 13 months), indexed by Calendar.JANUARY, Calendar.FEBRUARY, etc.

String months[] = null;

Also, getWeekdays() method returns 8 values and so on.

public final static int JANUARY = 0;
public final static int FEBRUARY = 1;
public final static int MARCH = 2;
public final static int APRIL = 3;
public final static int MAY = 4;
public final static int JUNE = 5;
public final static int JULY = 6;
public final static int AUGUST = 7;
public final static int SEPTEMBER = 8;
public final static int OCTOBER = 9;
public final static int NOVEMBER = 10;
public final static int DECEMBER = 11;
public final static int UNDECIMBER = 12;

The API describes UNDECIMBER as: field indicating the thirteenth month of the year. Although GregorianCalendar does not use this value, lunar calendars do.

Read here for such calendars.

like image 154
adi Avatar answered Feb 22 '26 04:02

adi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!