這是我的代碼,有點(diǎn)少,但能實(shí)現(xiàn)
package com.stu;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class testStringList {
?? ?/*
?? ? *利用Collections.sort()方法對(duì)泛型String的List進(jìn)行排序
?? ? *2.每條字符串的長(zhǎng)度為10以?xún)?nèi)的隨機(jī)整數(shù)
?? ? *3.每條字符串的每個(gè)字符都為隨機(jī)生成的字符,字符可以重復(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
你這個(gè)StringBuffer ?不能添加到List 里面排序,別鬧了
2015-09-24
你這個(gè)貌似只實(shí)現(xiàn)了隨機(jī)生成長(zhǎng)度10以?xún)?nèi)的字符串的功能,如何添加進(jìn)list再進(jìn)行排序呢?