类 SpringStringUtils
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static StringDelete any character in a givenString.static String[]delimitedListToStringArray(String str, String delimiter) Take aStringthat is a delimited list and convert it into aStringarray.static String[]delimitedListToStringArray(String str, String delimiter, String charsToDelete) Take aStringthat is a delimited list and convert it into aStringarray.static booleanhasLength(CharSequence str) Check that the givenCharSequenceis neithernullnor of length 0.static booleanCheck that the givenStringis neithernullnor of length 0.static booleanhasText(CharSequence str) Check whether the givenCharSequencecontains actual text.static booleanCheck whether the givenStringcontains actual text.static String[]Split aStringat the first occurrence of the delimiter.static PropertiessplitArrayElementsIntoProperties(String[] array, String delimiter) Take an array of strings and split each element based on the given delimiter.static PropertiessplitArrayElementsIntoProperties(String[] array, String delimiter, String charsToDelete) Take an array of strings and split each element based on the given delimiter.static String[]tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) static String[]toStringArray(Collection<String> collection) Copy the givenCollectioninto aStringarray.static String[]toStringArray(Enumeration<String> enumeration) Copy the given Enumeration into aStringarray.
-
构造器详细资料
-
SpringStringUtils
public SpringStringUtils()
-
-
方法详细资料
-
split
Split aStringat the first occurrence of the delimiter. Does not include the delimiter in the result.- 参数:
toSplit- the string to split (potentiallynullor empty)delimiter- to split the string up with (potentiallynullor empty)- 返回:
- a two element array with index 0 being before the delimiter, and
index 1 being after the delimiter (neither element includes the delimiter);
or
nullif the delimiter wasn't found in the given inputString
-
hasText
Check whether the givenCharSequencecontains actual text.More specifically, this method returns
trueif theCharSequenceis notnull, its length is greater than 0, and it contains at least one non-whitespace character.StringUtils.hasText(null) = false StringUtils.hasText("") = false StringUtils.hasText(" ") = false StringUtils.hasText("12345") = true StringUtils.hasText(" 12345 ") = true- 参数:
str- theCharSequenceto check (may benull)- 返回:
trueif theCharSequenceis notnull, its length is greater than 0, and it does not contain whitespace only- 另请参阅:
-
hasText
Check whether the givenStringcontains actual text.More specifically, this method returns
trueif theStringis notnull, its length is greater than 0, and it contains at least one non-whitespace character.- 参数:
str- theStringto check (may benull)- 返回:
trueif theStringis notnull, its length is greater than 0, and it does not contain whitespace only- 另请参阅:
-
hasLength
Check that the givenCharSequenceis neithernullnor of length 0.Note: this method returns
truefor aCharSequencethat purely consists of whitespace.StringUtils.hasLength(null) = false StringUtils.hasLength("") = false StringUtils.hasLength(" ") = true StringUtils.hasLength("Hello") = true- 参数:
str- theCharSequenceto check (may benull)- 返回:
trueif theCharSequenceis notnulland has length- 另请参阅:
-
hasLength
Check that the givenStringis neithernullnor of length 0.Note: this method returns
truefor aStringthat purely consists of whitespace.- 参数:
str- theStringto check (may benull)- 返回:
trueif theStringis notnulland has length- 另请参阅:
-
toStringArray
Copy the givenCollectioninto aStringarray.The
Collectionmust containStringelements only.- 参数:
collection- theCollectionto copy- 返回:
- the
Stringarray
-
toStringArray
Copy the given Enumeration into aStringarray. The Enumeration must containStringelements only.- 参数:
enumeration- the Enumeration to copy- 返回:
- the
Stringarray
-
delimitedListToStringArray
Take aStringthat is a delimited list and convert it into aStringarray.A single
delimitermay consist of more than one character, but it will still be considered as a single delimiter string, rather than as bunch of potential delimiter characters, in contrast totokenizeToStringArray(String, String, boolean, boolean).- 参数:
str- the inputString(potentiallynullor empty)delimiter- the delimiter between elements (this is a single delimiter, rather than a bunch individual delimiter characters)- 返回:
- an array of the tokens in the list
- 另请参阅:
-
delimitedListToStringArray
public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete) Take aStringthat is a delimited list and convert it into aStringarray.A single
delimitermay consist of more than one character, but it will still be considered as a single delimiter string, rather than as bunch of potential delimiter characters, in contrast totokenizeToStringArray(String, String, boolean, boolean).- 参数:
str- the inputString(potentiallynullor empty)delimiter- the delimiter between elements (this is a single delimiter, rather than a bunch individual delimiter characters)charsToDelete- a set of characters to delete; useful for deleting unwanted line breaks: e.g. "\r\n\f" will delete all new lines and line feeds in aString- 返回:
- an array of the tokens in the list
- 另请参阅:
-
deleteAny
-
tokenizeToStringArray
public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) Tokenize the givenStringinto aStringarray via aStringTokenizer.The given
delimitersstring can consist of any number of delimiter characters. Each of those characters can be used to separate tokens. A delimiter is always a single character; for multi-character delimiters, consider usingdelimitedListToStringArray(String, String).- 参数:
str- theStringto tokenize (potentiallynullor empty)delimiters- the delimiter characters, assembled as aString(each of the characters is individually considered as a delimiter)trimTokens- trim the tokens viaString.trim()ignoreEmptyTokens- omit empty tokens from the result array (only applies to tokens that are empty after trimming; StringTokenizer will not consider subsequent delimiters as token in the first place).- 返回:
- an array of the tokens
- 另请参阅:
-
splitArrayElementsIntoProperties
Take an array of strings and split each element based on the given delimiter. APropertiesinstance is then generated, with the left of the delimiter providing the key, and the right of the delimiter providing the value.Will trim both the key and value before adding them to the
Properties.- 参数:
array- the array to processdelimiter- to split each element using (typically the equals symbol)- 返回:
- a
Propertiesinstance representing the array contents, ornullif the array to process wasnullor empty
-
splitArrayElementsIntoProperties
public static Properties splitArrayElementsIntoProperties(String[] array, String delimiter, String charsToDelete) Take an array of strings and split each element based on the given delimiter. APropertiesinstance is then generated, with the left of the delimiter providing the key, and the right of the delimiter providing the value.Will trim both the key and value before adding them to the
Propertiesinstance.- 参数:
array- the array to processdelimiter- to split each element using (typically the equals symbol)charsToDelete- one or more characters to remove from each element prior to attempting the split operation (typically the quotation mark symbol), ornullif no removal should occur- 返回:
- a
Propertiesinstance representing the array contents, ornullif the array to process wasnullor empty
-