public class StringSplitter extends Object
| 构造器和说明 |
|---|
StringSplitter() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Collection<String> |
split(String str)
Splits the provided text into an array, using whitespace as the
separator.
|
static Collection<String> |
split(String str,
char separatorChar)
Splits the provided text into an array, separator specified.
|
static Collection<String> |
split(String str,
String separatorChars)
Splits the provided text into an array, separators specified.
|
static Collection<String> |
split(String str,
String separatorChars,
int max)
Splits the provided text into an array with a maximum length,
separators specified.
|
static Collection<String> |
splitByCharacterType(String str)
Splits a String by Character type as returned by
java.lang.Character.getType(char). |
static Collection<String> |
splitByCharacterTypeCamelCase(String str)
Splits a String by Character type as returned by
java.lang.Character.getType(char). |
static Collection<String> |
splitByWholeSeparator(String str,
String separator)
Splits the provided text into an array, separator string specified.
|
static Collection<String> |
splitByWholeSeparator(String str,
String separator,
int max)
Splits the provided text into an array, separator string specified.
|
static Collection<String> |
splitByWholeSeparatorPreserveAllTokens(String str,
String separator)
Splits the provided text into an array, separator string specified.
|
static Collection<String> |
splitByWholeSeparatorPreserveAllTokens(String str,
String separator,
int max)
Splits the provided text into an array, separator string specified.
|
static Collection<String> |
splitPreserveAllTokens(String str)
Splits the provided text into an array, using whitespace as the
separator, preserving all tokens, including empty tokens created by
adjacent separators.
|
static Collection<String> |
splitPreserveAllTokens(String str,
char separatorChar)
Splits the provided text into an array, separator specified,
preserving all tokens, including empty tokens created by adjacent
separators.
|
static Collection<String> |
splitPreserveAllTokens(String str,
String separatorChars)
Splits the provided text into an array, separators specified,
preserving all tokens, including empty tokens created by adjacent
separators.
|
static Collection<String> |
splitPreserveAllTokens(String str,
String separatorChars,
int max)
Splits the provided text into an array with a maximum length,
separators specified, preserving all tokens, including empty tokens
created by adjacent separators.
|
public static Collection<String> split(String str)
Splits the provided text into an array, using whitespace as the
separator.
Whitespace is defined by Character.isWhitespace(char).
The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A null input String returns null.
StringUtils.split(null) = null
StringUtils.split("") = []
StringUtils.split("abc def") = ["abc", "def"]
StringUtils.split("abc def") = ["abc", "def"]
StringUtils.split(" abc ") = ["abc"]
str - the String to parse, may be nullnull if null String inputpublic static Collection<String> split(String str, char separatorChar)
Splits the provided text into an array, separator specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A null input String returns null.
StringUtils.split(null, *) = null
StringUtils.split("", *) = []
StringUtils.split("a.b.c", '.') = ["a", "b", "c"]
StringUtils.split("a..b.c", '.') = ["a", "b", "c"]
StringUtils.split("a:b:c", '.') = ["a:b:c"]
StringUtils.split("a b c", ' ') = ["a", "b", "c"]
str - the String to parse, may be nullseparatorChar - the character used as the delimiternull if null String inputpublic static Collection<String> split(String str, String separatorChars)
Splits the provided text into an array, separators specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A null input String returns null.
A null separatorChars splits on whitespace.
StringUtils.split(null, *) = null
StringUtils.split("", *) = []
StringUtils.split("abc def", null) = ["abc", "def"]
StringUtils.split("abc def", " ") = ["abc", "def"]
StringUtils.split("abc def", " ") = ["abc", "def"]
StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
str - the String to parse, may be nullseparatorChars - the characters used as the delimiters,
null splits on whitespacenull if null String inputpublic static Collection<String> split(String str, String separatorChars, int max)
Splits the provided text into an array with a maximum length, separators specified.
The separator is not included in the returned String array. Adjacent separators are treated as one separator.
A null input String returns null.
A null separatorChars splits on whitespace.
If more than max delimited substrings are found, the last
returned string includes all characters after the first max - 1
returned strings (including separator characters).
StringUtils.split(null, *, *) = null
StringUtils.split("", *, *) = []
StringUtils.split("ab cd ef", null, 0) = ["ab", "cd", "ef"]
StringUtils.split("ab cd ef", null, 0) = ["ab", "cd", "ef"]
StringUtils.split("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"]
StringUtils.split("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
str - the String to parse, may be nullseparatorChars - the characters used as the delimiters,
null splits on whitespacemax - the maximum number of elements to include in the
array. A zero or negative value implies no limitnull if null String inputpublic static Collection<String> splitByCharacterType(String str)
Splits a String by Character type as returned by
java.lang.Character.getType(char). Groups of contiguous
characters of the same type are returned as complete tokens.
StringUtils.splitByCharacterType(null) = null
StringUtils.splitByCharacterType("") = []
StringUtils.splitByCharacterType("ab de fg") = ["ab", " ", "de", " ", "fg"]
StringUtils.splitByCharacterType("ab de fg") = ["ab", " ", "de", " ", "fg"]
StringUtils.splitByCharacterType("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"]
StringUtils.splitByCharacterType("number5") = ["number", "5"]
StringUtils.splitByCharacterType("fooBar") = ["foo", "B", "ar"]
StringUtils.splitByCharacterType("foo200Bar") = ["foo", "200", "B", "ar"]
StringUtils.splitByCharacterType("ASFRules") = ["ASFR", "ules"]
str - the String to split, may be nullnull if null String inputpublic static Collection<String> splitByCharacterTypeCamelCase(String str)
Splits a String by Character type as returned by
java.lang.Character.getType(char). Groups of contiguous
characters of the same type are returned as complete tokens, with the
following exception: the character of type
Character.UPPERCASE_LETTER, if any, immediately
preceding a token of type Character.LOWERCASE_LETTER
will belong to the following token rather than to the preceding, if any,
Character.UPPERCASE_LETTER token.
StringUtils.splitByCharacterTypeCamelCase(null) = null
StringUtils.splitByCharacterTypeCamelCase("") = []
StringUtils.splitByCharacterTypeCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"]
StringUtils.splitByCharacterTypeCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"]
StringUtils.splitByCharacterTypeCamelCase("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"]
StringUtils.splitByCharacterTypeCamelCase("number5") = ["number", "5"]
StringUtils.splitByCharacterTypeCamelCase("fooBar") = ["foo", "Bar"]
StringUtils.splitByCharacterTypeCamelCase("foo200Bar") = ["foo", "200", "Bar"]
StringUtils.splitByCharacterTypeCamelCase("ASFRules") = ["ASF", "Rules"]
str - the String to split, may be nullnull if null String inputpublic static Collection<String> splitByWholeSeparator(String str, String separator)
Splits the provided text into an array, separator string specified.
The separator(s) will not be included in the returned String array. Adjacent separators are treated as one separator.
A null input String returns null.
A null separator splits on whitespace.
StringUtils.splitByWholeSeparator(null, *) = null
StringUtils.splitByWholeSeparator("", *) = []
StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparator("ab:cd:ef", ":") = ["ab", "cd", "ef"]
StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]
str - the String to parse, may be nullseparator - String containing the String to be used as a delimiter,
null splits on whitespacenull if null String was inputpublic static Collection<String> splitByWholeSeparator(String str, String separator, int max)
Splits the provided text into an array, separator string specified.
Returns a maximum of max substrings.
The separator(s) will not be included in the returned String array. Adjacent separators are treated as one separator.
A null input String returns null.
A null separator splits on whitespace.
StringUtils.splitByWholeSeparator(null, *, *) = null
StringUtils.splitByWholeSeparator("", *, *) = []
StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparator("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"]
StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"]
str - the String to parse, may be nullseparator - String containing the String to be used as a delimiter,
null splits on whitespacemax - the maximum number of elements to include in the returned
array. A zero or negative value implies no limit.null if null String was inputpublic static Collection<String> splitByWholeSeparatorPreserveAllTokens(String str, String separator)
Splits the provided text into an array, separator string specified.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A null input String returns null.
A null separator splits on whitespace.
StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *) = null
StringUtils.splitByWholeSeparatorPreserveAllTokens("", *) = []
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "", "", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]
str - the String to parse, may be nullseparator - String containing the String to be used as a delimiter,
null splits on whitespacenull if null String was inputpublic static Collection<String> splitByWholeSeparatorPreserveAllTokens(String str, String separator, int max)
Splits the provided text into an array, separator string specified.
Returns a maximum of max substrings.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A null input String returns null.
A null separator splits on whitespace.
StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *, *) = null
StringUtils.splitByWholeSeparatorPreserveAllTokens("", *, *) = []
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 0) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 0) = ["ab", "", "", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"]
str - the String to parse, may be nullseparator - String containing the String to be used as a delimiter,
null splits on whitespacemax - the maximum number of elements to include in the returned
array. A zero or negative value implies no limit.null if null String was inputpublic static Collection<String> splitPreserveAllTokens(String str)
Splits the provided text into an array, using whitespace as the
separator, preserving all tokens, including empty tokens created by
adjacent separators. This is an alternative to using StringTokenizer.
Whitespace is defined by Character.isWhitespace(char).
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A null input String returns null.
StringUtils.splitPreserveAllTokens(null) = null
StringUtils.splitPreserveAllTokens("") = []
StringUtils.splitPreserveAllTokens("abc def") = ["abc", "def"]
StringUtils.splitPreserveAllTokens("abc def") = ["abc", "", "def"]
StringUtils.splitPreserveAllTokens(" abc ") = ["", "abc", ""]
str - the String to parse, may be nullnull if null String inputpublic static Collection<String> splitPreserveAllTokens(String str, char separatorChar)
Splits the provided text into an array, separator specified, preserving all tokens, including empty tokens created by adjacent separators. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A null input String returns null.
StringUtils.splitPreserveAllTokens(null, *) = null
StringUtils.splitPreserveAllTokens("", *) = []
StringUtils.splitPreserveAllTokens("a.b.c", '.') = ["a", "b", "c"]
StringUtils.splitPreserveAllTokens("a..b.c", '.') = ["a", "", "b", "c"]
StringUtils.splitPreserveAllTokens("a:b:c", '.') = ["a:b:c"]
StringUtils.splitPreserveAllTokens("a\tb\nc", null) = ["a", "b", "c"]
StringUtils.splitPreserveAllTokens("a b c", ' ') = ["a", "b", "c"]
StringUtils.splitPreserveAllTokens("a b c ", ' ') = ["a", "b", "c", ""]
StringUtils.splitPreserveAllTokens("a b c ", ' ') = ["a", "b", "c", "", ""]
StringUtils.splitPreserveAllTokens(" a b c", ' ') = ["", a", "b", "c"]
StringUtils.splitPreserveAllTokens(" a b c", ' ') = ["", "", a", "b", "c"]
StringUtils.splitPreserveAllTokens(" a b c ", ' ') = ["", a", "b", "c", ""]
str - the String to parse, may be nullseparatorChar - the character used as the delimiter,
null splits on whitespacenull if null String inputpublic static Collection<String> splitPreserveAllTokens(String str, String separatorChars)
Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A null input String returns null.
A null separatorChars splits on whitespace.
StringUtils.splitPreserveAllTokens(null, *) = null
StringUtils.splitPreserveAllTokens("", *) = []
StringUtils.splitPreserveAllTokens("abc def", null) = ["abc", "def"]
StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "def"]
StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "", def"]
StringUtils.splitPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"]
StringUtils.splitPreserveAllTokens("ab:cd:ef:", ":") = ["ab", "cd", "ef", ""]
StringUtils.splitPreserveAllTokens("ab:cd:ef::", ":") = ["ab", "cd", "ef", "", ""]
StringUtils.splitPreserveAllTokens("ab::cd:ef", ":") = ["ab", "", cd", "ef"]
StringUtils.splitPreserveAllTokens(":cd:ef", ":") = ["", cd", "ef"]
StringUtils.splitPreserveAllTokens("::cd:ef", ":") = ["", "", cd", "ef"]
StringUtils.splitPreserveAllTokens(":cd:ef:", ":") = ["", cd", "ef", ""]
str - the String to parse, may be nullseparatorChars - the characters used as the delimiters,
null splits on whitespacenull if null String inputpublic static Collection<String> splitPreserveAllTokens(String str, String separatorChars, int max)
Splits the provided text into an array with a maximum length, separators specified, preserving all tokens, including empty tokens created by adjacent separators.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. Adjacent separators are treated as one separator.
A null input String returns null.
A null separatorChars splits on whitespace.
If more than max delimited substrings are found, the last
returned string includes all characters after the first max - 1
returned strings (including separator characters).
StringUtils.splitPreserveAllTokens(null, *, *) = null
StringUtils.splitPreserveAllTokens("", *, *) = []
StringUtils.splitPreserveAllTokens("ab de fg", null, 0) = ["ab", "de", "fg"]
StringUtils.splitPreserveAllTokens("ab de fg", null, 0) = ["ab", "", "", "de", "fg"]
StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"]
StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 2) = ["ab", "cd:ef"]
StringUtils.splitPreserveAllTokens("ab de fg", null, 2) = ["ab", " de fg"]
StringUtils.splitPreserveAllTokens("ab de fg", null, 3) = ["ab", "", " de fg"]
StringUtils.splitPreserveAllTokens("ab de fg", null, 4) = ["ab", "", "", "de fg"]
str - the String to parse, may be nullseparatorChars - the characters used as the delimiters,
null splits on whitespacemax - the maximum number of elements to include in the
array. A zero or negative value implies no limitnull if null String inputCopyright © 2022. All rights reserved.