You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicstaticvoidshuffle(List<?> list) {
Randomrnd = r;
if (rnd == null)
r = rnd = newRandom(); // harmless race.shuffle(list, rnd);
}
privatestaticRandomr;
@SuppressWarnings({"rawtypes", "unchecked"})
publicstaticvoidshuffle(List<?> list, Randomrnd) {
intsize = list.size();
if (size < SHUFFLE_THRESHOLD || listinstanceofRandomAccess) {
for (inti=size; i>1; i--)
swap(list, i-1, rnd.nextInt(i));
} else {
Object[] arr = list.toArray();
// Shuffle arrayfor (inti=size; i>1; i--)
swap(arr, i-1, rnd.nextInt(i));
// Dump array back into list// instead of using a raw type here, it's possible to capture// the wildcard but it will require a call to a supplementary// private methodListIteratorit = list.listIterator();
for (Objecte : arr) {
it.next();
it.set(e);
}
}
}
publicstaticvoidmain(String[] args) {
List<Integer> list = newArrayList<>();
for (inti = 0; i < 10; i++) {
list.add(i);
}
System.out.println(list);
Collections.shuffle(list);
System.out.println(list);
Collections.shuffle(list);
System.out.println(list);
}
The text was updated successfully, but these errors were encountered:
Collections.shuffle()
The text was updated successfully, but these errors were encountered: