交作业了!!!
屏蔽的部分是判断重复不重复的
屏蔽的部分是判断重复不重复的
2020-03-25
package collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.UUID;
public class collectionTest {
public void testSort3() {
List<String> stList = new ArrayList<String>();
Random random = new Random();
String randomStr;
for(int i=0;i<10;i++) {
int R = random.nextInt(10);
do {
randomStr = UUID.randomUUID().toString().substring(0, R);
}while(stList.contains(randomStr));
stList.add(randomStr);
System.out.println("将要添加字符串:"+randomStr);
}
System.out.println("-----排序前-----");
for(String s:stList) {
System.out.println("元素:"+s);
}
Collections.sort(stList);
System.out.println("-----排序后-----");
for(String s:stList) {
System.out.println("元素:"+s);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
collectionTest ct = new collectionTest();
// ct.testSort1();
// ct.testSort2();
ct.testSort3();
}
举报