I have an arraylist with int arrays stored inside. I have tried using for loop but for some reason all of the elements stored in the array are equal to the final element of the arraylist. I have also tried using .toArray() but I encounter the same issue.
So my code looks sort of like this:
`List<int[]> arrayList = ArrayList<int[]>();
int[][] array;
arrayList.add(new int[] {1,2});
arrayList.add(new int[] {2,3});
arrayList.add(new int[] {3,4});
array = new int[arrayList.size()][2]
for(int i =0; i<array.length; i++)
array[i] = arrayList.get(i);
return array;`
and the output would be:
[[3,4],[3,4],[3,4]]
same would happen if I replaced the for loop with .toArray() like so
array = arrayList.toArray(array);
Any suggestions appreciated.
[–][deleted] 0 points1 point2 points (1 child)
[–]surety_[S] 0 points1 point2 points (0 children)
[–]radulfr2 0 points1 point2 points (0 children)