Monday, 15 February 2010

java - Problems converting Array of objects to ArrayList -



java - Problems converting Array of objects to ArrayList -

i have created object contains results query ran against database. these results stored in array.

i trying convert array arraylist can used import document.

i have tried:

//trustsummary name of array arraylist info = new arraylist(arrays.aslist(trustsummary));

but appears causing issues (classcastexception) when trying run below code in part of application. please able point in right direction resolve issue.

for (iterator rows = data.iterator(); rows.hasnext();) arraylist row = (arraylist) rows.next();

the arraylist(collection) constructor using here in part write new arraylist(arrays.aslist(trustsummary)); creates arraylist elements source collection, not create arraylist collection element.

so need either prepare line, or alter line

arraylist row = (arraylist) rows.next();

to

trustsummary ts = (trustsummary) rows.next();

generally advise using generics, avoid sort of confusion regarding collection's types.

in case either example

list<trustsummary> summaries = new arraylist<trustsummary>(arrays.aslist(trustsummary));

java arrays arraylist

No comments:

Post a Comment