交作业了................
import java.util.ArrayList;
import java.util.Random;
import java.util.Collections;
public class Tester{
ArrayList <String> string = new ArrayList<String>();
Random random = new Random();
public static void main(String [] args){
Tester tester = new Tester();
tester.sort();
System.out.println("********Before sort*******");
for(int i = 0;i < tester.string.size(); i++){
System.out.println(tester.string.get(i));
}
System.out.println("********After sort*******");
Collections.sort(tester.string);
for(String temp: tester.string){
System.out.println(temp);
}
}
public void sort(){
String s = "";
for(int i = 0; i < 10; i++){
do{
s = createString();
}while(string.contains(s));
System.out.println("Element: "+s);
string.add(s);
}
}
public String createString(){
String str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
StringBuilder sb = new StringBuilder();
int number = (random.nextInt(9)+1);
do{
sb.append(str.charAt(random.nextInt(str.length())));
number--;
}while(number >0);
return sb.toString();
}
}