I created a list of int arrays, and I want to return it as a 2D array.
List<int[]> ans = new ArrayList<>();
int[][] toReturn = new int[ans.size()][];
return ans.toArray(toReturn);
How does this code work? What is the difference between list.toArray() and list.toArray(T[] a)?
List<List<Integer>>would work too, by the way