新手小白,望大神指导!
public void testSort4(){
List<String> stringList = new ArrayList<String>();
String stringBase = "0123456789abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String sb ="" ;
char[] ch;
Random random = new Random();
for (int i = 0; i < 10; i++) {
do{
int temp = random.nextInt(10);
ch = new char[temp];
for(int j = 0;j < temp;j++ ){
int temp2 = random.nextInt(stringBase.length());
char ch2 = stringBase.charAt(temp2);
ch[j] = ch2;
}
sb = sb.valueOf(ch);
}while(stringList.contains(sb));
System.out.println("将要添加的字符串是:"+sb);
stringList.add(sb);
}
System.out.println("-----------排序前---------------");
for (String string : stringList) {
System.out.println("元素:"+string);
}
System.out.println("-----------排序后---------------");
Collections.sort(stringList);
for (String string : stringList) {
System.out.println("元素:"+string);
}
}
2025 - 快车库 - 我的知识库 重庆启连科技有限公司 渝ICP备16002641号-10
企客连连 表单助手 企服开发 榜单123