java - Save a LocalDate list to an array[][] -


i save dates list array[][]?

my list is

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>();     (localdate date = start;          date.isbefore(end);          date = date.plusdays(1))     {         int day = date.getdayofweek();         // these passed in...         if (day == datetimeconstants.sunday)         {             result.add(date);         }     }     return result; }    

i used :

string[] sundayarray = dates.toarray(new string[dates.size()]); system.out.println(sundayarray[5]); 

this error output:

exception in thread "main" java.lang.arraystoreexception      @ java.lang.system.arraycopy(native method)      @ java.util.arraylist.toarray(unknown source)      @ test.main(test.java:27) 

line 27 string[] sundayarray = dates.toarray(new string[dates.size()]);

i'll guess error comes on line:

string[][] sundayarray = dates.toarray(new string[dates.size()]); 

you gave method one-dimensional array (new string[dates.size()]) , tried make two-dimensional array (string[][] sundayarray).

you're trying implicitly convert list<localdate> string[] isn't possible. arraystoreexception comes when try store localdate in string. you'll need more like:

list<string> temp = new arraylist(dates.size()); (localdate date : dates) {     temp.add(date.tostring()); //tostring() or appropriate method } string[] sundayarray = temp.toarray(new string[dates.size()]); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -