Reputation: 21
String Hello = "abc";
rowValue.add(Hello);
completeData.add(rowValue);
System.out.println(" One " +completeData);
rowValue.clear();
String value= "def";
rowValue.add(value);
completeData.add(rowValue);
System.out.println(" Two " +completeData);
Output: One [[abc]] Two [[def], [def]]...
How to get output as: One [[abc]] TWo [[abc], [def]]
I am not sure, What is happening after Clear() function call.
Upvotes: 0
Views: 32
Reputation: 201447
Don't call clear
. You are adding one reference. Change
rowValue.clear();
to something like
rowValue = new ArrayList<>();
Upvotes: 1