package com.changshaheima.demo;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
public class CallTheRoll {
public static void main(String[] args) {
String[] name = { "zsd", "b++", "c++", "d++", "asd", "bbc", "eea", "ssd",
"sdad", "das", "fff", "qqq", "www", "eee", "rrr", "ttt", "yyy" };
// demo1(name); //数组实现
demo2(name); // 集合实现
}
private static void demo2(String[] name) {
ArrayList arr = new ArrayList();
for (int i = 0; i < name.length; i++) {
arr.add(name[i]);
}
System.out.println(arr.get(new Random().nextInt(arr.size())));
}
private static void demo1(String[] name) {
String obtain = name[new Random().nextInt(name.length)];
System.out.println( obtain); // 数组实现
}
}
|
|