java随机打乱集合顺序

时间:2023-11-10 20:45:26
public static void main(String[] args) {
List <Integer> intList = new ArrayList<Integer>(); //汉字随机放入的位子
intList.add(1);
intList.add(2);
intList.add(3);
intList.add(4);
Collections.shuffle(intList);
for (int i = 0; i < intList.size(); i++) {
System.out.println(intList.get(i));
} System.out.println("-----------------"); Integer[] arr = new Integer[] {1, 2, 3, 4};
List<Integer> list = Arrays.asList(arr);
Collections.shuffle(list);
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}