fevernova
2016-03-07 16:14
public void testStringSort2(){ //创建一个String泛型的List对象 List<String> stringList = new ArrayList<String>(); //创建一个字符表 char[] character = {'0','1','2','3','4','5','6','7','8','9','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', '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'}; //创建一个随机数生成器 Random random = new Random(); //创建一个String对象接收生成字符串 String str = ""; //生成十个长度在10以内的随机字符串 for(int i = 0; i < 10; i++){ for(int j = 0; j < random.nextInt(10)+1; j++){ str += character[random.nextInt(62)]; } stringList.add(str); System.out.println("成功添加字符串:" + str); str = ""; } //把排序前后List进行比较 System.out.println("----------------排序前------------------"); for (String string : stringList) { System.out.println("元素:" + string); } Collections.sort(stringList); System.out.println("----------------排序后------------------"); for (String string : stringList) { System.out.println("元素:" + string); } }
Sorry, I don't understand
what do you want to say??
Java入门第三季
409792 学习 · 4340 问题
相似问题