- public static void main(String[] args) {
- ArrayList list = method();
- Iterator iterator = list.iterator();
- while (iterator.hasNext()) {
- Object object = (Object) iterator.next();
- System.out.print(object + " ");
- }
-
- private static ArrayList method() {
- Random random = new Random();
- ArrayList list = new ArrayList();
- while (list.size() < 10) {
- int a = random.nextInt(100) + 1;
- if (!list.contains(a)) {
- list.add(a);
- }
- }
- return list;
- }
- }
复制代码 |