我想將列表中的日期保存到數組[] []?將LocalDate列表保存到數組[] []
我的目錄是
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()]);
一維列表無法進入二維數組。你在[5] [1]期待什麼? –