public class Demo14StringSplit {
public static void main(String[] args) {
String str1="aaa,bbb,ccc,ddd,eee,fff";
String[] split = str1.split(",");
for(int i=0;i<split.length;i++){
System.out.println(split[i]);
}
System.out.println("========================");
String str2="aaa.bbb.ccc.ddd.eee.fff";
//不应该用.特殊情况
String[] split1 = str2.split(".");
System.out.println("split1的长度为====="+split1.length);
for (int i = 0; i < split1.length; i++) {
System.out.println(split1[i]);
}
//应该用\\.
System.out.println("正确结果来啦===========");
String[] split2 = str2.split("\\.");
System.out.println("split1的长度为====="+split2.length);
for (int i = 0; i < split2.length; i++) {
System.out.println(split2[i]);
}
}
}
输出为: