public void testStringSort() {
List<String> stringList = new ArrayList<String>();
String stringSource = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char[] stringArr = stringSource.toCharArray();
Random random = new Random();
for(int i=0;i<10;i++) {
StringBuilder str = new StringBuilder("");
int h = (int)(Math.random()*10+1);
do {
for(int p = 0;p<h;p++) {
int num = (int)(Math.random() * stringArr.length);
str.append(stringArr[num]);
}
}while(stringList.contains(str));
String strNew = ""+str;
stringList.add(strNew);
}
System.out.println("-----------排序前--------------------");
for(String str1:stringList) {
System.out.println("元素:"+str1);
}
Collections.sort(stringList);
System.out.println("-----------排序后--------------------");
for(String str2:stringList) {
System.out.println("元素:"+str2);
}
}
添加回答
举报
0/150
提交
取消