I am using the following code and at the end i saw in calssEntries list the last values duplicated
i mean if i debug it i can see the right data but in the second iteration the values of the first data entries
are override and i see the second twice and so on
what i 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();
for (int i = 1; i < dataArray.length; i += 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 the problem is that you need to create a new instance of memberList and memberValueList in the while loop. Something like:
In your code, entries of calssEntries are referring to the same(single) instance of memberList and memberValue.