I'm trying to populate a list with string arrays but the only array that is added to the list is the last added. And this seems to be added to all list elements.
What am I doing wrong?
String[] indata = new String[2];
List<String[]> ls = new ArrayList<String[]>();
indata[0]="test1";
indata[1]="test2";
ls.add(indata);
indata[0]="test3";
indata[1]="test4";
ls.add(indata);
for(int index=0; index < ls.size(); index++)
System.out.println("ZZZZZZZZZZZZ----->> " + index + " " + Arrays.toString(ls.get(index)));
Expected output:
ZZZZZZZZZZZZ----->> 0 [test1, test2]
ZZZZZZZZZZZZ----->> 1 [test3, test4]
Actual output:
ZZZZZZZZZZZZ----->> 0 [test3, test4]
ZZZZZZZZZZZZ----->> 1 [test3, test4]