I noticed that the base int array changes according to how the list is created:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class Shuffling {
static Integer[] intArr = {1, 2, 3, 4, 5};
static Random random = new Random(7);
public static void main(String[] args) {
List<Integer> intList = new ArrayList<Integer>(Arrays.asList(intArr));
Collections.shuffle(intList, random);
System.out.println("List after shuffling: " + intList);
System.out.println("intArr: " + Arrays.toString(intArr));
List<Integer> intList2 = Arrays.asList(intArr);
Collections.shuffle(intList2, random);
System.out.println("List2 after shuffling: " + intList2);
System.out.println("intArr: " + Arrays.toString(intArr));
}
}
Why is this happening?
source
share