java 字符串split有很多坑,使用时请小心!!

 
 
  System.out.println(":ab:cd:ef::".split(":").length);//末尾分隔符全部忽略  
  System.out.println(":ab:cd:ef::".split(":",-1).length);//不忽略任何一个分隔符  
  System.out.println(StringUtils.split(":ab:cd:ef::",":").length);//最前面的和末尾的分隔符全部都忽略,apache commons  
  System.out.println(StringUtils.splitPreserveAllTokens(":ab:cd:ef::",":").length);//不忽略任何一个分隔符 apache commons   
输出:  
4  
6  
3  
6  


猜你喜欢

转载自blog.csdn.net/qq_35384887/article/details/79092801
今日推荐