這是我的代碼,有點少,但能實現(xiàn)
package com.stu;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class testStringList {
?? ?/*
?? ? *利用Collections.sort()方法對泛型String的List進行排序
?? ? *2.每條字符串的長度為10以內(nèi)的隨機整數(shù)
?? ? *3.每條字符串的每個字符都為隨機生成的字符,字符可以重復(fù)
?? ? */
?? ?
??? public void testsort(){
?? ??? ?List<String> stringList = new ArrayList<String>();
?? ??? ?String base = "1234567890qwertyuiopasdfghjklzxcvbnmQAZWSXEDCRFVTGBYHNUJMIKOLP";
?? ??? ?for(int i=0;i<10;i++){
?? ??? ??? ?StringBuilder sb =new StringBuilder();
?? ??? ??? ?Random random =new Random();
?? ??? ??? ?int k= random.nextInt(9)+1;
?? ??? ??? ?for(int j=0;j<k;j++){
?? ??? ??? ??? ?int c=random.nextInt(61);
??????????? sb.append(base.charAt(c));
?? ??? ??? ?}
?? ??? ??? ?System.out.println(sb); ??? ??? ?
?? ??? ?}
??? }
?? ?/**
?? ? * @param args
?? ? */
?? ?public static void main(String[] args) {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?testStringList tsl = new testStringList();
?? ??? ?tsl.testsort();
?? ?}
}
2015-09-24
你這個StringBuffer ?不能添加到List 里面排序,別鬧了
2015-09-24
你這個貌似只實現(xiàn)了隨機生成長度10以內(nèi)的字符串的功能,如何添加進list再進行排序呢?