String split方法 当在末尾含有空字符时尤其应注意
String a = ",,";
System.out.println(a.split(",").length);//0
System.out.println(a.split(",",-1).length);//3
a = ",,1";
System.out.println(a.split(",").length);//3
System.out.println(a.split(",",-1).length);//3
a = "1,,";
System.out.println(a.split(",").length);//1
System.out.println(a.split(",",-1).length);//3
没有评论:
发表评论