小技巧 為List新增分隔符

2021-09-24 08:31:55 字數 624 閱讀 7272

public static void join1

() system.out.println(sb.tostring());

//如果想要加個分隔符,比如逗號,傳統寫法:

sb = new stringbuilder();

for(int i = 0; i < list.size(); i++)

}system.out.println(sb.tostring());

//使用commons-lang庫寫法, 其實這個已經夠簡單了,就這個功能而言,我很喜歡,而且最最常用:

system.out.println(stringutils.join(list.toarray(), ","));

//進入jdk8時代:

system.out.println(list.stream().collect(collectors.joining()));

//jdk8時代,加個分隔符:

system.out.println(list.stream().collect(collectors.joining(",")));

}複製**

文章:www.jianshu.com/p/7932c144e…

日常JS彙總 金額自動新增分隔符

function currencyformat input,e d g var whichcode window.event e.which e.keycode 獲取當前使用者輸入的鍵盤 alert 鍵盤輸入值 whichcode if whichcode 13 return true 如果使用者輸...

多列轉一列,並加分隔符

create table table 1 id int,name varchar 8 go insert into table 1 select 1,tom union all select 2,john union all select 3,jerry go輸出結果 1,2,3 declare s...

mysql按條件匯出資料(txt),並加分隔符

select name,reno into outfile var lib mysql files test1.txt fields terminated by from test where reno 000 我這裡是在linux環境下測試的 這裡分隔符是 會將test表中按條件reno 000 ...