public class test {
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
Random random=new Random();
for (int i = 0; i < 15; i++)
{
int n=random.nextInt(15);//产生随机数
list.add(new Integer(n));
}
System.out.println("打乱前顺序为:");
System.out.println(list);
for (int i = 0; i < 3; i++) {
System.out.println("第" + i + "次打乱:");
Collections.shuffle(list);
System.out.println(list);
}
}
}
结果:
打乱前顺序为:
[9, 3, 14, 5, 2, 0, 0, 3, 12, 4, 13, 4, 11, 2, 3]
第0次打乱:
[12, 9, 2, 11, 0, 3, 5, 0, 2, 3, 14, 3, 13, 4, 4]
第1次打乱:
[4, 9, 14, 5, 4, 2, 0, 13, 11, 2, 3, 3, 12, 3, 0]
第2次打乱:
[4, 13, 0, 5, 9, 14, 2, 0, 3, 3, 12, 2, 3, 11, 4]