java - Duplicate entries inside loop of list<String> -
i using next code , @ end saw in calssentries list lastly values duplicated mean if debug can see right info in sec iteration values of first info entries override , see sec twice , on miss here?
string membername = null; string membervalue = null; list<string> memberlist = new arraylist<string>(); list<string> membervaluelist = new arraylist<string>();+arraylist<classentry> calssentries = new arraylist<classentry>(); ... while (datarow != null) { memberlist.clear(); membervaluelist.clear(); (int = 1; < dataarray.length; += 2) { membername = dataarray[i]; memberlist.add(membername); membervalue = dataarray[i + 1]; membervaluelist.add(membervalue); } classentry classentry = new classentry(); classentry.setclassname(classname); classentry.setmembername(memberlist); classentry.setmembervalue(membervaluelist); calssentries.add(classentry); ....
i think problem need create new instance of memberlist , membervaluelist in while loop. like:
calssentries = new arraylist<classentry>(); ... while (datarow != null) { list<string> memberlist = new arraylist<string>(); list<string> membervaluelist = new arraylist<string>(); ... ...
in code, entries of calssentries referring same(single) instance of memberlist , membervalue.
java list arraylist
No comments:
Post a Comment