我想将列表中的日期保存到数组[][]?
我的清单是
List<LocalDate> dates = getWeekendDates
(new LocalDate(year, month, (day+2)), new LocalDate((year+1), nymonth ,nyday));
private static List<LocalDate> getWeekendDates
(LocalDate start, LocalDate end)
{
List<LocalDate> result = new ArrayList<LocalDate>();
for (LocalDate date = start;
date.isBefore(end);
date = date.plusDays(1))
{
int day = date.getDayOfWeek();
// These could be passed in...
if (day == DateTimeConstants.SUNDAY)
{
result.add(date);
}
}
return result;
}
我用了 :
String[] SundayArray = dates.toArray(new String[dates.size()]);
System.out.println(SundayArray[5]);
这是错误输出:
Exception in thread "main" java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at java.util.ArrayList.toArray(Unknown Source)
at Test.main(Test.java:27)
第 27 行是String[] SundayArray = dates.toArray(new String[dates.size()]);