public void testSort3(){ String stringClass="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; StringBuilder sc = new StringBuilder() ; List<String> stringList = new ArrayList<String>(); Random random=new Random(); String s=new String(); int temp=0; while (temp<10) { do { int r=random.nextInt(10)+1; for (int i = 0; i < r; i++) { // 每条字符串的每个字符都为随机生成的字符,字符可以重复 int j =random.nextInt(63); //获取每个单个字符 char c = stringClass.charAt(j); //往sc追加字符 sc.append(c); } s=sc.toString(); sc.delete(0,sc.length()); }while (stringList.contains(s)); stringList.add(s); System.out.println("成功添加字符串:"+s); temp++; } System.out.println("---------------排序前-------------"); for (String string:stringList) { System.out.print(string+" "); } //调用sort方法进行排序 Collections.sort(stringList); System.out.println("\n---------------排序后-------------"); for (String string:stringList) { System.out.print(string+" "); } } /** * * @param args */ public static void main(String []args){ CollectionsTest ct=new CollectionsTest(); //ct.testSort1(); //ct.testSort2(); ct.testSort3(); }
你好,请问为什么是63?10个数字加26*2个字母不应该是62吗?还有,我的字符串里会出现空的,算不算正常现象呢
sc.delete(0,sc.length());请问这个是什么意思
这是我的正确代码,和你们分享一下