这里只有随机生成十位长度为1-10的字符串,打印输出没写
Random random = new Random();
List<String> list = new ArrayList<String>();
String string = "0123456789qwertyuioplkjhgfdsazxcvbnm0123456789QWERTYUIOPLKJHGFDASZXCVBNM";
for (int i = 0; i < 10; i++) {
int length = (int) (Math.random() * 10 + 1);
StringBuilder sb = new StringBuilder();
for (int j = 0; j < length; j++) {
do {
char str = string.charAt(random.nextInt(string.length()));
sb.append(str);
} while (list.contains(sb));
}
list.add(sb.toString());
}
Random random = new Random(); List<String> list = new ArrayList<String>(); String string = "0123456789qwertyuioplkjhgfdsazxcvbnm0123456789QWERTYUIOPLKJHGFDASZXCVBNM"; for (int i = 0; i < 10; i++) { int length = (int) (Math.random() * 10 + 1); StringBuilder sb = new StringBuilder(); for (int j = 0; j < length; j++) { char str = string.charAt(random.nextInt(string.length())); sb.append(str); } list.add(sb.toString()); }
是要把10个随机的字符串放进list里面吗?
把list.add()放进for循环里;