public class ListSort { public void sort(){ //首先需要一个字母数字组合的字符串 String string = "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0123456789"; //初始化字符串 StringBuilder newstring = new StringBuilder(); Random random = new Random(); List<StringBuilder> list = new ArrayList<StringBuilder>(); for(int i = 0;i < 10; i++){ for(int j = 10;j > 0;j--){ int a = random.nextInt(61); char c = string.charAt(a); newstring = newstring.append(c); } list.add(newstring); newstring = new StringBuilder(); } System.out.println("排序前---------------"); for(StringBuilder string2:list){ System.out.println(string2); } System.out.println("排序后---------------"); Collections.sort(list); for(StringBuilder string2:list){ System.out.println(string2); } } public static void main(String[] args) { // TODO Auto-generated method stub ListSort ls = new ListSort(); ls.sort(); }}
添加回答
举报
0/150
提交
取消