- import java.util.*;
- class Random {
- public static void main(String[] args) {
- Object s[] = { "abc1", "abc2", "abc3", "abc4", "abc5" };
- method(s);
- }
- public static void method(Object[] news2) {
- if (news2.length == 0)
- return;
- List<Object> list = new ArrayList<Object>();
- for (Object str : news2) {
- list.add(str);
- }
- int len = list.size();
- int x = (int) (Math.random() * len);
- Object str = list.remove(x);
- System.out.println(str);
- Object[] news = null;
- news = list.toArray();
- method(news);
- }
- }
复制代码 |