import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class Test {
private static List<String> stringList;
private static String finalString;
public static void main(String[] args) {
stringList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
do {
createString();
} while (stringList.contains(finalString));
stringList.add(finalString);
}
System.out.println("————————————————————————排序前——————————————————————————");
listOut(stringList);
Collections.sort(stringList);
System.out.println("————————————————————————排序后——————————————————————————");
listOut(stringList);
}
private static void createString() {
Random random = new Random();
StringBuffer sb = new StringBuffer();
int length = random.nextInt(10)+1;
for (int i = 0; i < length; i++) {
int type = random.nextInt(3);
switch (type) {
case 0:
int[] num = {
0,1,2,3,4,5,6,7,8,9,
};
sb.append(num[random.nextInt(10)]);
break;
case 1:
char[] capital = {
'Q','W','E','R','T','U','I','O','P','A','S',
'D','F','G','H','J','K','L','Z','X','C','V',
'B','N','M','Y'
};
sb.append(capital[random.nextInt(26)]);
break;
case 2:
char[] lowercase = {
'q','w','e','r','t','y','u','i','o','p',
'a','s','d','f','g','h','j','k','l','z',
'x','c','v','b','n','m'
};
sb.append(lowercase[random.nextInt(26)]);
break;
default:
break;
}
}
finalString = sb.toString();
}
private static void listOut(List<String> stringList) {
for (String string : stringList) {
System.out.println("元素:"+string);
}
}
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦