练习的代码运行出来以后首行是空值,帮忙指点一下呗
package com.collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class test {
public void testSort(){
List<String>stringList=new ArrayList<String>();
//添加10条随机字符串,每条字符串的长度为10以内的随机整数
Random random=new Random();
int x;
int f;
String y;
String k="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for(int i=0;i<10;i++){
do{
x=random.nextInt(61);
f=random.nextInt(61);
y="";
if(x>f&&x-f<10){
y=k.substring(f,x);
}
if(x<f&&f-x<10){
y=k.substring(x,f);
}else{
continue;
}
}while(stringList.contains(y));
stringList.add(y);
System.out.println("将要添加字符串:"+y);
}
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);
}
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
test t=new test();
t.testSort();
}
}