分隔字符串.返回分隔后的字符串数组
stringObj.split([separator,[limit]])
第一个参数是个正则表达式, 第二个参数可选
public static void split拆分字符串(){
//split vt.
分裂;分开;
String s1 = "hello there";
String s3 = "this is a test";
String[] s2 =
s1.split("e");//返回"h","llo th","r"
//按s分隔成两个 就是按第一个s来分
//split("s",3);
按s分隔成三个 就是按第一个第二个s来分 返回"thi","
i"," a test"
String[] s4 = s3.split("s",2);
//返回"thi"和" is a test"
System.out.println("length:"+s2.length);
for(String s:s2){
System.out.println(s);
}
System.out.println("length:"+s4.length);
for(String s:s4){
System.out.println(s);
}
System.out.println("--------------------------------------------------------");
//上面的都简单.
本文深入解析Java中split方法的功能与用法,通过实例展示如何利用正则表达式和limit参数实现字符串的高效分割。涵盖基本用法、参数影响以及常见应用场景。
3989

被折叠的 条评论
为什么被折叠?



