注意: String.split()方法不会把最后的空字符串放到结果数组中

比如 "!!!!2!!!4
!!!!".split( "!").length =
8 ,也就是说“4”之后的空字符串没人管了

要解决这个问题,可以用 org.apache.commons.lang.StringUtils.splitPreserveAllTokens

比如,对上面同样的字符串,StringUtils.splitPreserveAllTokens("!!!!2!!!4!!!!", "!").length =
12

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.