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]);
}结果:
立即学习“Java免费学习笔记(深入)”;
boo,and:foo
当limit
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] + " ");
}
}结果:
立即学习“Java免费学习笔记(深入)”;
boo and foo
当limit=0时,应用无限次并省略末尾的空字符串
名扬银河企业建站系统,适用于无代码基础的新手,快速搭建企业网站,程序内置了多项实用功能及插件,能够便捷的对网站进行修改、调整、优化等方面进行操作。【部分功能介绍】1、产品管理发布企业产品信息,管理企业产品,自定义产品封面图,产品详情图、文、视频,产品扩展属性自定义等。2、案例管理系统发布企业成功案例,管理成功案例,自定义案例封面图,案例详情图、文、视频,案例扩展属性自定义等。3、资讯管理系统发布企
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] + ")");
}
}结果:
立即学习“Java免费学习笔记(深入)”;
(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] + ")");
}
}结果:
立即学习“Java免费学习笔记(深入)”;
(b),(),(:and:f)
以上就是对Java split 的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!
更多java split用法详解及实例代码相关文章请关注PHP中文网!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号