Collections.shuffle(List) has a time complexity of O(n) . You can use Arrays.asList() to wrap an array so you can use this function.
What is he doing
For each element from the last to the second element, we exchange the element for a random element from the rest of the list, which includes itself, that is, it may not accidentally move the element.
for (int i=size; i>1; i--) swap(list, i-1, rnd.nextInt(i));
source share