課程
/后端開發
/Java
/Java入門第三季
屏蔽的部分是判斷重復不重復的
2020-03-25
源自:Java入門第三季 6-5
正在回答
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("-----排序后-----");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
collectionTest ct = new collectionTest();
// ct.testSort1();
// ct.testSort2();?
ct.testSort3();
舉報
Java中你必須懂得常用技能,不容錯過的精彩,快來加入吧
3 回答交作業了?。。。。。?/p>
2 回答交作業了?。?!
2 回答交作業交作業
1 回答來交作業了
1 回答交作業交作業拉?。?!
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2020-04-02
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();
}