關(guān)于隨機(jī)字符串的生成
這里只有隨機(jī)生成十位長(zhǎng)度為1-10的字符串,打印輸出沒(méi)寫(xiě)
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());
}
2016-07-21
2016-07-12
是要把10個(gè)隨機(jī)的字符串放進(jìn)list里面嗎?
把list.add()放進(jìn)for循環(huán)里;