java split用法詳解及實(shí)例代碼
public String[] split(String regex) 默認(rèn)limit為0
public String[] split(String regex, int limit)
當(dāng)limit>0時(shí),則應(yīng)用n-1次
public static void main(String[] args) { String s = "boo:and:foo"; String[] str = s.split(":",2); System.out.print(str[0] + "," + str[1]); }
結(jié)果:
boo,and:foo
當(dāng)limit<0時(shí),則應(yīng)用無(wú)限次
public static void main(String[] args) { String s = "boo:and:foo"; String[] str = s.split(":",-2); for(int i = 0 ; i < str.length ; i++){ System.out.print(str[i] + " "); } }
結(jié)果:
boo and foo
當(dāng)limit=0時(shí),應(yīng)用無(wú)限次并省略末尾的空字符串
public static void main(String[] args) { String s = "boo:and:foo"; String[] str = s.split("o",-2); for(int i = 0 ; i < str.length ; i++){ if( i < str.length - 1) System.out.print("(" + str[i] + "),"); else System.out.print("(" + str[i] + ")"); } }
結(jié)果:
(b),(),(:and:f),(),()
public static void main(String[] args) { String s = "boo:and:foo"; String[] str = s.split("o",0); for(int i = 0 ; i < str.length ; i++){ if( i < str.length - 1) System.out.print("(" + str[i] + "),"); else System.out.print("(" + str[i] + ")"); } }
結(jié)果:
(b),(),(:and:f)
以上就是對(duì)Java split 的資料整理,后續(xù)繼續(xù)補(bǔ)充相關(guān)資料,謝謝大家對(duì)本站的支持!
相關(guān)文章
IntelliJ IDEA2019實(shí)現(xiàn)Web項(xiàng)目創(chuàng)建示例
這篇文章主要介紹了IntelliJ IDEA2019實(shí)現(xiàn)Web項(xiàng)目創(chuàng)建示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04簡(jiǎn)單的一次springMVC路由跳轉(zhuǎn)實(shí)現(xiàn)
本文主要介紹了springMVC路由跳轉(zhuǎn)實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04java web中的servlet3 upload上傳文件實(shí)踐
這篇文章主要介紹了servlet3 upload上傳文件實(shí)踐,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-11-11深入探究 spring-boot-starter-parent的作用
這篇文章主要介紹了spring-boot-starter-parent的作用詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,感興趣的小伙伴可以跟著小編一起來(lái)學(xué)習(xí)一下2023-05-05SpringBoot實(shí)現(xiàn)動(dòng)態(tài)定時(shí)任務(wù)的示例代碼
在SpringBoot項(xiàng)目中簡(jiǎn)單使用定時(shí)任務(wù),不過(guò)由于要借助cron表達(dá)式且都提前定義好放在配置文件里,不能在項(xiàng)目運(yùn)行中動(dòng)態(tài)修改任務(wù)執(zhí)行時(shí)間,實(shí)在不太靈活?,F(xiàn)在我們就來(lái)實(shí)現(xiàn)可以動(dòng)態(tài)修改cron表達(dá)式的定時(shí)任務(wù),感興趣的可以了解一下2022-10-10java并發(fā)編程之進(jìn)程和線程調(diào)度基礎(chǔ)詳解
這篇文章主要介紹了java并發(fā)編程之進(jìn)程和線程調(diào)度基礎(chǔ),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06