/**
* 生成十条随机字符串
* 字符串的长度是10以内的随机数
* 且字符串不能重复
*/
public void testSort3() {
List<String> lists = new ArrayList<String>();
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random = new Random();
String string;
for (int i = 0; i < 10; i++) {
StringBuilder sb = new StringBuilder();
int length = random.nextInt(10);
do {
for (int j = 0; j < length; j++) {
int number = random.nextInt(62);
sb.append(str.charAt(number));
}
string = sb.toString();
} while (lists.contains(string));
lists.add(string);
}
System.out.println("----------sorted before---------------");
for (String element : lists) {
System.out.println(element);
}
Collections.sort(lists);
System.out.println("----------sorted after---------------");
for (String element : lists) {
System.out.println(element);
}
}点击查看更多内容
2人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦