I’m trying to pass a List<String[]> between functions but I got a weird result.
The function!
public List<String[]> tes(){
List<String[]> test = new ArrayList<String[]>();
String[] temp = {"a","b","c"};
test.add(temp);
temp[0] = "d";
temp[1] = "e";
temp[2] = "f";
test.add(temp);
return test;
}
The extraction.
String output = "";
List<String[]> Results = db.tes();
for (String[] row: Results) {
output = output + row[0] + " " + row[1] + "\n";
}
Result:
d e
d e
I really don’t get it. It should be a b d e, but it’s not.
You have one object temp. It means that all object in list have link on your alone temp. Try use
newfor each string and your result will be different.Good luck!