提问题口气还这么嚣张,你以为这个题目很难?难个P,再加个难度吧,集合元素由系统随机生成
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Iterator;
- import java.util.ListIterator;
- import java.util.Random;
- public class aaa {
- public static void main(String[] args) {
- ArrayList<String> list = new ArrayList<>();
-
- for (int i = 0; i < 1000; i++) {
- list.add(StringNum(3));
- }
- ListIterator lit = list.listIterator();
- ArrayList<String> newList = new ArrayList<>();
- while (lit.hasNext()) {
- String str = (String)lit.next();
- boolean falg = true;
- for (int i = 0; i <= 9; i++) {
- String si = str.valueOf(i);
- if (str.contains(si)) {
- falg = false;
- continue;
- }
- }
- if (falg) {
- newList.add(str);
- }
- }
- System.out.println(newList);
- }
- public static String StringNum(int length) {
-
- String az = "adbefcghijklmnopqrstuvxyz1234567890";
- Random rand = new Random();
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < length; i++) {
- int number = rand.nextInt(az.length());
- sb.append(az.charAt(number));
- }
- return sb.toString();
-
- }
- }
复制代码
|