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 的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!
如对本文有疑问, 点击进行留言回复!!
ScrollView和RecyclerView的滑动事件处理
配置JAVA环境+安装Android Studio全过程+踩坑记录
Android P Camera2当SD卡被拔出来自动切换到内部存储
android 多个edittext 判空监听 让Button动态是否可点击
Android开源项目滚轮选择器WheelPicker的基本用法总结
网友评论