亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

類型不適用?

類型不適用?

Meng7y 2017-07-05 20:25:12
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();?? ?}}
查看完整描述

3 回答

?
精慕門9254224

TA貢獻167條經驗 獲得超46個贊

StringBuider 的拼接直接用append 加在后面就可以了,你卻又用個newstring 來接收!

查看完整回答
反對 回復 2017-07-08
?
緋翼

TA貢獻9條經驗 獲得超6個贊

把list的數據類型改為string

查看完整回答
反對 回復 2017-07-08
  • 3 回答
  • 0 關注
  • 1691 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號