国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

java split用法詳解及實例代碼

2019-11-26 13:48:24
字體:
來源:轉載
供稿:網友

public String[] split(String regex) 默認limit為0

public String[] split(String regex, int limit)

當limit>0時,則應用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]); }

結果:

boo,and:foo

當limit<0時,則應用無限次

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] + " ");    } }

結果:

boo and foo

當limit=0時,應用無限次并省略末尾的空字符串

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] + ")");    } }

結果:

(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] + ")");    } }

結果:

(b),(),(:and:f)

以上就是對Java split 的資料整理,后續繼續補充相關資料,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武定县| 龙陵县| 江津市| 乌拉特后旗| 常宁市| 扎赉特旗| 平南县| 兴文县| 新沂市| 南召县| 巢湖市| 曲阳县| 禹州市| 孟连| 怀来县| 兴仁县| 阜康市| 张掖市| 玉田县| 闸北区| 濮阳县| 牡丹江市| 漳平市| 准格尔旗| 含山县| 南雄市| 巴彦淖尔市| 奉贤区| 商城县| 阿拉善左旗| 纳雍县| 明光市| 马龙县| 元氏县| 固始县| 洞头县| 盐池县| 荔波县| 张家港市| 深州市| 肥东县|