Does ArrayList.get(index) return only the value of the element at index or a pointer to this element? I ask this because this doesn't perform as I expect it to
List<List<Integer>> myList;
myList = new ArrayList<>(Collections.nCopies(n, new ArrayList<>()));
.
.
.
List tempList = this.myList.get(x);
tempList.add(i);
this.myList.set(i,tempList);
Instead of adding an element to the array at index x, and storing the new list at index i, it is appending the element at both spots so instead of a list increasing in size, I get n times the last element