| |
17. 23. 14. 改组名单:随机重新排序清单 |
|
public static void shuffle(List list)
public static void shuffle(List list, Random rnd)
|
|
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class MainClass {
public static void main(String args[]) {
String s[] = { "A", "B", "C", "D", "E", "H", "I" };
List list1 = Arrays.asList(s);
List list2 = Arrays.asList(s);
Random rand = new Random(100);
Collections.shuffle(list1, rand);
Collections.shuffle(list2, rand);
System.out.println(list1);
System.out.println(list2);
}
}
|
|
[H, D, A, E, C, B, I]
[H, D, A, E, C, B, I] |
|