程序编译通过,但是运行后报异常,求大神帮忙
package com.studet.course;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class ListSort {
public ListSort()
{
}
public void testCollections() {
List<String> listStrings = new ArrayList<String>();
Random random = new Random();
for (int i = 0; i < 10; i++) {
String temp = "";
do{
int length = random.nextInt(9)+1;
temp = "";
for(int j = 0;j < length; j++){
temp = temp + randomString();
}
}while(listStrings.contains(temp));
listStrings.add(temp);
System.out.println("添加成功"+temp);
}
System.out.println("-------排序前---------");
for (String string : listStrings) {
System.out.println(string);
}
Collections.sort(listStrings);
System.out.println("---------排序后--------");
for (String string : listStrings) {
System.out.println(string);
}
}
public char randomString() {
String str = "0123456789qwertyuioplkjhgfdsamnbvcxzQWERTYUIOPLKJHGFDSAZXCVBNM";
Random random = new Random();
char c = str.charAt(random.nextInt(64));
return c;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ListSort test = new ListSort();
test.testCollections();
//test.randomString();
}
}