I have an ArrayList< int[] > and would like to convert this to an int[][]. The resulting array has the same int[] for each entry even though they are distinct (yes, I've checked!). Am I missing something simple here? The length of the arrays in int[][] is given by arr.length
int[][] vals = new int[ list.size() ][ arr.length ];
list.toArray( vals );
EDIT: I've realized that the code works ok, so heres a larger sample of the code where the problem is arising. permute() does as it says and permutes the integers in the given array returning true when a new permutation is done.
List< int[] > list = new ArrayList<>();
do {
list.add( vals );
} while ( permute( vals ) ); // I print vals here and the permutations are all unique each time
int[][] permutations = new int[ list.size() ][];
list.toArray( permutations );
// If I print permutations now, all the arrays inside it are the same
arr.lengthisn't necessary, and it doesn't really matter what you put in there because the elements of the outer array are references that will get overwritten anyway. You can just make it[].)