I am getting very frustrated because I cannot seem to figure out why Collections shuffling is not working properly.
Lets say that I am trying to shuffle the randomizer array.
int[] randomizer = new int[] {200,300,212,111,6,2332}; Collections.shuffle(Arrays.asList(randomizer));
For some reason the elements stay sorted exactly the same whether or not I call the shuffle method. Any ideas?
Arrays.asListcannot be used with arrays of primitives. Use this instead:The same rule applies to most classes in the collections framework, in that you can’t use primitive types.
The original code (with
int[]) compiled fine, but did not work as intended, because of the behaviour of the variadic methodasList: it just makes a one-element list, with theintarray as its only member.