public void testSort3(){
//随机十个字符串段,
//每个字符串段都不相同
//每个字符串段的位数也不相同
//重新排列字符串段
List<String> zifuList = new ArrayList<String>();//创建一个新的集合对象
char[] zf = {'a','b','c','d','e','f','d','h','i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G'
,'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X'
,'Y','Z','0','1','2','3','4','5','6','7','8','9','@','$'};//包含足够的字符
Random random = new Random();//创建一个随机数,
for(int j = 0;j<10;j++){
String U= new String();
do{
for(int i=0;i<random.nextInt(zf.length)+1;i++){
U += String.valueOf(zf[random.nextInt(zf.length)]);
}
}while(zifuList.contains(U));
zifuList.add(U);
System.out.println("已添加元素:"+U);
}
System.out.println("***********排序前***************");
for(String ss:zifuList){
System.out.println(ss);
}
Collections.sort(zifuList);
System.out.println("***********排序后前***************");
for(String ss:zifuList){
System.out.println(ss);
}
}
public void testRandom(){
Random rm = new Random();
for(int k=0;k<10;k++){
System.out.println(rm.nextInt(10));
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
CollectionsTest cl = new CollectionsTest();
cl.testSort3();
//cl.testRandom();
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦