java中collections类的shuffle方法是怎么实现的
1个回答
展开全部
// ShuffleTest.java
import java.util.*;
public class ShuffleTest {
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < 10; i++)
list.add(new Integer(i));
System.out.println("打乱前:");
System.out.println(list);
for (int i = 0; i < 5; i++) {
System.out.println("第" + i + "次打乱:");
Collections.shuffle(list);
System.out.println(list);
}
}
}
import java.util.*;
public class ShuffleTest {
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < 10; i++)
list.add(new Integer(i));
System.out.println("打乱前:");
System.out.println(list);
for (int i = 0; i < 5; i++) {
System.out.println("第" + i + "次打乱:");
Collections.shuffle(list);
System.out.println(list);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询