package wzs.arithmetics;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
//打乱数据顺序
public class Test_wzs34
{
public static void main(String[] args)
{
List<Integer> arr = new ArrayList<Integer>();
for (int i = 1; i <= 10; i++)
{
arr.add(i);
}
System.out.println("打乱前:");
for (int i : arr)
{
System.out.print(i + " ");
}
Collections.shuffle(arr);
System.out.println("\n打乱后:");
for (int i : arr)
{
System.out.print(i + " ");
}
}
}
输出结果:
打乱前:
1 2 3 4 5 6 7 8 9 10
打乱后:
4 7 9 10 1 5 6 3 2 8