package com.imooc.collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class Testsort {
public int qiusuijishu(int length)
{
Random random=new Random();
int k=random.nextInt(length);
return k;
}
public String shengchengsuijizifuchuan(int changdu)
{
String choose="1234567890abcdefghijklmnopqrstABCDEFGHIGKLMNOPQRST";
StringBuffer sBuffer=new StringBuffer();
int length=choose.length();
for(int i=0;i<changdu;i++)
{
sBuffer.append(choose.charAt(qiusuijishu(length-1)));
}
return sBuffer.toString();
}
public void sort3()
{
Random two=new Random();
List<String> newlist3=new ArrayList<String>();
for(int i=0;i<10;i++)
{
int k=two.nextInt(62);
newlist3.add(shengchengsuijizifuchuan(k));
}
System.out.println("排序前字符串为");
shuchu(newlist3);
Collections.sort(newlist3);
System.out.println("排序后的字符串为");
shuchu(newlist3);
}
public void shuchu(List newlist)
{
for (Object url : newlist) {
System.out.println(url);
}
}
public static void main(String[] args)
{
Testsort one=new Testsort();
one.sort3();
}
}
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦