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

