您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

java split用法详解及实例代码

2026/1/29 3:25:24发布13次查看
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 的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!
更多java split用法详解及实例代码。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product