为了账号安全,请及时绑定邮箱和手机立即绑定

第三季6.5排序(单个字符串不包含重复字符)

标签:
Java
package com.sort;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.SynchronousQueue;
public class Ctest {
    static List<String> list=new ArrayList<String>();
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    Ctest n=new Ctest();
    n.TextAdd();
    n.TestSort();
     
    }
    public static void TextAdd() {
        Random random = new Random();
        for(int i=0;i<10;) {
            int length = random.nextInt(10)+1; 
            StringBuilder str=new StringBuilder();
            for(int j=0;j<length;) {
                int order=random.nextInt(123);
                if(order>=48&&order<=57) {
                    char ch=(char)order;
                    if(str.toString().contains("ch")) {
                        continue;
                    }else {
                        str.append(ch);
                        j++;
                    }
                    
                }else if(order>=65&&order<=90) {
                    char ch=(char)order;
                    if(str.toString().contains("ch")) {
                        continue;
                    }else {
                        str.append(ch);
                        j++;
                    
                }}else if(order>=97) {
                    char ch =(char )order;
                    if(str.toString().contains("ch")) {
                        continue;
                    }else {
                        str.append(ch);
                        j++;
                    
                }}else {
                    continue;
                }
                
                }
            
            if(list.contains(str.toString()) ){
                continue;
            }
            else {
                list.add(str.toString());
                i++;
            }
        }
    }
       public void textforeach() {
           for (String string:list) {
               System.out.println(string);
           }
       }
       public void TestSort() {       
           System.out.println("--------排序前--------");        
           textforeach();        
           System.out.println("--------排序后--------");        
           Collections.sort(list);        
           textforeach();    }  
    }
点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 1
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消