哪里有问题?一直提示strList改为静态static
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class TempTest {
List<StringBuilder> strList=new ArrayList<StringBuilder>();
public static void main(String[] args) {
// TODO Auto-generated method stub
String st="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
StringBuilder strbd=new StringBuilder();
//StringBuilder str;
Random random=new Random();
for (int i = 0; i < 10; i++) {
do {
int length=random.nextInt(10);
for (int j = 0; j < length; j++) {
strbd.append(st.charAt(random.nextInt(62)));
}
} while (strList.contains(strbd));
strList.add(strbd);
}
System.out.println("---------------排序前--------------------");
for(StringBuilder sl : strList)
System.out.println(sl);
Collections.sort(strList);
System.out.println("---------------排序后--------------------");
for(StringBuilder sl : strList)
System.out.println(sl);
}
}