package cn.edu.lin.task;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
* Created by asus on 2016/11/4.
*/
public class CollectionsTask {
public static List<String> listRandomString() {
String str = "qwertyuiopasdfghjklzxcvbnmQWERRTYUIOPASDFGHJKLZXCVBNM1234567890";
Random random = new Random();
List<String> listString = new ArrayList<String>();
String[] strArray = new String[10];
for (int i = 0; i < 10; i++) {
StringBuffer stringBuffer = new StringBuffer();
//确定字符串长度
int size = (int) (Math.random() * 10);
for (int j = 0; j < size; j++) {
int index = random.nextInt(str.length());
char c = str.charAt(index);
stringBuffer.append(c);
}
if (!(listString.contains(stringBuffer.toString()))) {
listString.add(stringBuffer.toString());
} else {
i--;
}
}
return listString;
}
public static void main(String[] args){
List<String > strList = listRandomString();
System.out.println("--------生成10条随机字符串--------");
for(String string : strList){
System.out.println(string);
}
System.out.println("--------排序后-------------");
Collections.sort(strList);
for(String string :strList){
System.out.println(string);
}
}
}
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦