public void testRandomStringSort() {
List<String> strings = new ArrayList<String>();
String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random = new Random();
for (int i = 0; i < 10; i++) {
StringBuffer sb = new StringBuffer();
do {
for (int j = 0; j < random.nextInt(9)+1; j++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
} while (strings.contains(sb));
System.out.println("成功添加10位以内不重复随机字符串"+sb);
strings.add(sb.toString());
}
System.out.println("---------排序前--------");
for (String string : strings) {
System.out.println("元素:"+string);
}
Collections.sort(strings);
System.out.println("---------排序后--------");
for (String string : strings) {
System.out.println("元素:"+string);
}
}
2025 - 快车库 - 我的知识库 重庆启连科技有限公司 渝ICP备16002641号-10
企客连连 表单助手 企服开发 榜单123