import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
* Created by DELL on 2019/7/22.
*/
public class CollectionsTest1 {
public void testSort() {
List<String> list = new ArrayList<>();
Random random = new Random();
String s =new String();
for (int i = 0; i < 10; i++) {
do {
int w = s.length();
Integer k = random.nextInt(10);
w = k;
s = randomString(w);
} while (list.contains(s));
list.add(s);
}
System.out.println("----------排序前------------");
for (String string : list) {
System.out.println("随机字符串:" + string);
}
Collections.sort(list);
System.out.println("-------排序后-------");
for (String string : list) {
System.out.println("随机字符" + string);
}
}
public String randomString(int sun) {
String s = "";
Random r = new Random();
for (int j = 0; j < 10; j++) {
s = s + (char) Math.abs(r.nextInt(26) % 26 + 96);
}
return s;
}
public static void main(String[] ages) {
CollectionsTest1 st = new CollectionsTest1();
st.testSort();
}
}