美文网首页
java的字符串sort

java的字符串sort

作者: 庶庶 | 来源:发表于2016-09-15 00:43 被阅读0次

    package com.imooc;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    import java.util.Random;

    ···
    public class testSort {
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    List<String>stringList=new ArrayList<String>();
    Random random=new Random();
    String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    StringBuffer sb;
    for(int i=0;i<10;i++)
    {
    sb=new StringBuffer();
    int length=(int)(Math.random()*9)+1;
    do{
    for(int j=0;j<length;j++)
    {
    int number=random.nextInt(base.length());
    sb.append(base.charAt(number));
    }
    }while(stringList.contains(sb));
    stringList.add(sb.toString());
    System.out.println("将要添加的字符串:" + sb.toString());
    }
    System.out.println("------排序前------");
    for (String string : stringList)
    { System.out.println("元素:" + string); }
    System.out.println("------排序后------");
    Collections.sort(stringList);
    for (String string : stringList)
    { System.out.println("元素:" + string); }
    }

    }
    ···

    相关文章

      网友评论

          本文标题:java的字符串sort

          本文链接:https://www.haomeiwen.com/subject/upcbettx.html