課程
/后端開發(fā)
/Java
/Java入門第三季
屏蔽的部分是判斷重復(fù)不重復(fù)的
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 回答交作業(yè)了?。。。。?!
2 回答交作業(yè)了?。?!
2 回答交作業(yè)交作業(yè)
1 回答來交作業(yè)了
1 回答交作業(yè)交作業(yè)拉!?。?/p>
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
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();
}