Method | Description | Example |
Splitter.on(char) | Split on occurrences of a specific, individual character. | Splitter.on(‘;‘) |
Splitter.on(CharMatcher) | Split on occurrences of any character in some category. | Splitter.on(CharMatcher.BREAKING_WHITESPACE) Splitter.on(CharMatcher.anyOf(";,.")) |
Splitter.on(String) | Split on a literal String. | Splitter.on(", ") |
Splitter.on(Pattern) Splitter.onPattern(String) |
Split on a regular expression. | Splitter.onPattern("\r?\n") |
Splitter.fixedLength(int) | Splits strings into substrings of the specified fixed length. The last piece can be smaller than length, but will never be empty. | Splitter.fixedLength(3) |
Method | Description | Example |
omitEmptyStrings() | Automatically omits empty strings from the result. | Splitter.on(‘,‘).omitEmptyStrings(). split("a,,c,d") returns "a", "c", "d" |
trimResults() | Trims whitespace from the results; equivalent totrimResults(CharMatcher.WHITESPACE). | Splitter.on(‘,‘).trimResults().split ("a, b, c, d") returns "a", "b", "c", "d" |
trimResults(CharMatcher) | Trims characters matching the specified CharMatcher from results. | Splitter.on(‘,‘).trimResults (CharMatcher.is(‘_‘)).split("_a ,_b_ ,c__") returns "a ", "b_ ", "c". |
limit(int) | Stops splitting after the specified number of strings have been returned. | Splitter.on(‘,‘).limit(3).split ("a,b,c,d") returns "a", "b", "c,d" |
guava的String之Splitter,布布扣,bubuko.com
原文地址:http://blog.csdn.net/qunzer/article/details/25376633