horse2
2016-05-09 12:08
List<String> stringList = new ArrayList<String>();
Random random = new Random();
String basic = "0123456789abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(int i=0;i<10;i++){
StringBuffer sb = new StringBuffer();
int num = random.nextInt(10)+1;
do{
for(int j=0;j<num;j++){
int number = random.nextInt(basic.length());
sb.append(basic.charAt(number));
}
}while(stringList.contains(sb));
String stringSb =sb.toString();
stringList.add(stringSb);
System.out.println("添加了字符串:"+stringSb);
}
System.out.println("------------排序前-------------");
for (String string : stringList) {
System.out.println("元素:"+string);
}
Collections.sort(stringList);
System.out.println("------------排序后-------------");
for (String string : stringList) {
System.out.println("元素:"+string);
中的int number = random.nextInt(basic.length());
后面的能够理解,但是前期的int number 有些不太确定是什么意思
Java入门第三季
409792 学习 · 4340 问题
相似问题