类 StringUtils
- 作者:
- Nacos, zzq
-
字段概要
字段 -
方法概要
修饰符和类型方法说明static StringapplyRelativePath(String path, String relativePath) Apply the given relative path to the given Java resource path, assuming standard Java folder separation (i.e. "/" separators).static Stringcapitalize(String str) Capitalize aString, changing the first letter to upper case as perCharacter.toUpperCase(char).static StringNormalize the path by suppressing sequences like "path/.." and inner simple dots.static StringcollectionToDelimitedString(Collection<?> coll, String delim) Convert aCollectioninto a delimitedString(e.g.static StringcollectionToDelimitedString(Collection<?> coll, String delim, String prefix, String suffix) Convert aCollectionto a delimitedString(e.g.static booleancontains(CharSequence str, CharSequence searchStr) Checks if CharSequence contains a search CharSequence.static booleancontainsIgnoreCase(CharSequence str, CharSequence searchStr) Checks if CharSequence contains a search CharSequence irrespective of case, handlingnull.static StringReturns either the passed in CharSequence, or if the CharSequence is empty ornullor whitespace only, the value ofEmptyString.static StringdefaultIfBlank(String str, String defaultStr) Returns either the passed in CharSequence, or if the CharSequence is empty ornullor whitespace only, the value ofdefaultStr.static StringdefaultIfEmpty(String str, String defaultStr) Returns either the passed in CharSequence, or if the CharSequence is empty ornull, the value ofdefaultStr.static StringDelete any character in a givenString.static StringdeleteWhitespace(String str) Deletes all whitespaces from a String as defined byCharacter.isWhitespace(char).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 booleanCompares two CharSequences, returningtrueif they represent equal sequences of characters.static booleanequalsIgnoreCase(String str1, String str2) Compares two CharSequences, returningtrueif they represent equal sequences of characters, ignoring case.static StringgetFilename(String path) Extract the filename from the given Java resource path, e.g.static booleanCheck that the givenStringis neithernullnor of length 0.static booleanCheck whether the givenStringcontains actual text.static booleanisAnyBlank(CharSequence... css) Checks if any one of the CharSequences are blank ("") or null and not whitespace only..static booleanisBlank(CharSequence cs) Checks if a string is empty (""), null and whitespace only.static booleanChecks if a str is empty ("") or null.static booleanisNoneBlank(CharSequence... css) Checks if none of the CharSequences are blank ("") or null and whitespace only..static booleanisNotBlank(String str) Checks if a string is not empty (""), not null and not whitespace only.static booleanisNotEmpty(String str) Checks if a str is not empty ("") or not null.static Stringjoin(Collection collection, String separator) Joins the elements of the provided array into a single String containing the provided list of elements.static StringnewStringForUtf8(byte[] bytes) Create a string with encoding format as utf8.static StringReplace all occurrences of a substring within a string with another string.static String[]Splits the provided text into an array with a maximum length, separators specified.static booleanstartsWith(CharSequence str, CharSequence prefix) Check if a CharSequence starts with a specified prefix.static booleanstartsWithIgnoreCase(CharSequence str, CharSequence prefix) Case insensitive check if a CharSequence starts with a specified prefix.static StringsubstringBetween(String str, String open, String close) Substring between two index.static String[]tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) static String[]toStringArray(Collection<String> collection) Copy the givenCollectioninto aStringarray.static StringRemoves control characters (char <= 32) from both ends of this String, handlingnullby returningnull.
-
字段详细资料
-
方法详细资料
-
newStringForUtf8
Create a string with encoding format as utf8.
- 参数:
bytes- the bytes that make up the string- 返回:
- created string
-
isBlank
Checks if a string is empty (""), null and whitespace only.
- 参数:
cs- the string to check- 返回:
trueif the string is empty and null and whitespace
-
isNotBlank
Checks if a string is not empty (""), not null and not whitespace only.
- 参数:
str- the string to check, may be null- 返回:
trueif the string is not empty and not null and not whitespace
-
isNotEmpty
Checks if a str is not empty ("") or not null.
- 参数:
str- the str to check, may be null- 返回:
trueif the str is not empty or not null
-
isEmpty
Checks if a str is empty ("") or null.
- 参数:
str- the str to check, may be null- 返回:
trueif the str is empty or null
-
defaultIfEmpty
Returns either the passed in CharSequence, or if the CharSequence is empty or
null, the value ofdefaultStr.- 参数:
str- the CharSequence to check, may be nulldefaultStr- the default CharSequence to return if the input is empty ("") ornull, may be null- 返回:
- the passed in CharSequence, or the default
-
defaultIfBlank
Returns either the passed in CharSequence, or if the CharSequence is empty or
nullor whitespace only, the value ofdefaultStr.- 参数:
str- the CharSequence to check, may be null, may be whitespace onlydefaultStr- the default CharSequence to return if the input is empty ("") ornull, may be null- 返回:
- the passed in CharSequence, or the default
-
defaultEmptyIfBlank
Returns either the passed in CharSequence, or if the CharSequence is empty or
nullor whitespace only, the value ofEmptyString.- 参数:
str- the CharSequence to check, may be null, may be whitespace only- 返回:
- the passed in CharSequence, or the empty string
-
equals
Compares two CharSequences, returning
trueif they represent equal sequences of characters.- 参数:
str1- the first string, may benullstr2- the second string, may benull- 返回:
trueif the string are equal (case-sensitive), or bothnull- 另请参阅:
-
trim
Removes control characters (char <= 32) from both ends of this String, handling
nullby returningnull.- 参数:
str- the String to be trimmed, may be null- 返回:
- the trimmed string,
nullif null String input
-
substringBetween
Substring between two index.- 参数:
str- stringopen- start index to subclose- end index to sub- 返回:
- substring
-
join
Joins the elements of the provided array into a single String containing the provided list of elements.
- 参数:
collection- the Collection of values to join together, may be nullseparator- the separator string to use- 返回:
- the joined String,
nullif null array input
-
containsIgnoreCase
Checks if CharSequence contains a search CharSequence irrespective of case, handlingnull. Case-insensitivity is defined as byString.equalsIgnoreCase(String).A
nullCharSequence will returnfalse.- 参数:
str- the CharSequence to check, may be nullsearchStr- the CharSequence to find, may be null- 返回:
- true if the CharSequence contains the search CharSequence irrespective of case or false if not or
nullstring input
-
contains
Checks if CharSequence contains a search CharSequence.- 参数:
str- the CharSequence to check, may be nullsearchStr- the CharSequence to find, may be null- 返回:
- true if the CharSequence contains the search CharSequence
-
isNoneBlank
Checks if none of the CharSequences are blank ("") or null and whitespace only..
- 参数:
css- the CharSequences to check, may be null or empty- 返回:
trueif none of the CharSequences are blank or null or whitespace only
-
isAnyBlank
Checks if any one of the CharSequences are blank ("") or null and not whitespace only..
- 参数:
css- the CharSequences to check, may be null or empty- 返回:
trueif any of the CharSequences are blank or null or whitespace only
-
startsWith
Check if a CharSequence starts with a specified prefix.
nulls are handled without exceptions. Twonullreferences are considered to be equal. The comparison is case sensitive.- 参数:
str- the CharSequence to check, may be nullprefix- the prefix to find, may be null- 返回:
trueif the CharSequence starts with the prefix, case sensitive, or bothnull- 另请参阅:
-
startsWithIgnoreCase
Case insensitive check if a CharSequence starts with a specified prefix.
nulls are handled without exceptions. Twonullreferences are considered to be equal. The comparison is case insensitive.- 参数:
str- the CharSequence to check, may be nullprefix- the prefix to find, may be null- 返回:
trueif the CharSequence starts with the prefix, case insensitive, or bothnull- 另请参阅:
-
deleteWhitespace
Deletes all whitespaces from a String as defined by
Character.isWhitespace(char).- 参数:
str- the String to delete whitespace from, may be null- 返回:
- the String without whitespaces,
nullif null String input
-
equalsIgnoreCase
Compares two CharSequences, returning
trueif they represent equal sequences of characters, ignoring case.- 参数:
str1- the first string, may be nullstr2- the second string, may be null- 返回:
trueif the string are equal, case insensitive, or bothnull
-
split
Splits the provided text into an array with a maximum length, separators specified. If separatorChars is empty, divide by blank.- 参数:
str- the String to parse, may be null- 返回:
- an array of parsed Strings
-
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;- 参数:
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
- 另请参阅:
-
toStringArray
- 参数:
collection- theCollectionto copy (potentiallynullor empty)- 返回:
- the resulting
Stringarray
-
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 (maybenull)- 返回:
trueif theStringis notnull, its length is greater than 0, and it does not contain whitespace only- 另请参阅:
-
cleanPath
Normalize the path by suppressing sequences like "path/.." and inner simple dots.The result is convenient for path comparison. For other uses, notice that Windows separators ("\") are replaced by simple slashes.
NOTE that
cleanPathshould not be depended upon in a security context. Other mechanisms should be used to prevent path-traversal issues.- 参数:
path- the original path- 返回:
- the normalized path
-
collectionToDelimitedString
Convert aCollectioninto a delimitedString(e.g. CSV).Useful for
toString()implementations.- 参数:
coll- theCollectionto convert (potentiallynullor empty)delim- the delimiter to use (typically a ",")- 返回:
- the delimited
String
-
collectionToDelimitedString
public static String collectionToDelimitedString(Collection<?> coll, String delim, String prefix, String suffix) - 参数:
coll- theCollectionto convert (potentiallynullor empty)delim- the delimiter to use (typically a ",")prefix- theStringto start each element withsuffix- theStringto end each element with- 返回:
- the delimited
String
-
hasLength
Check that the givenStringis neithernullnor of length 0.Note: this method returns
truefor aStringthat purely consists of whitespace.- 参数:
str- theStringto check (maybenull)- 返回:
trueif theStringis notnulland has length- 另请参阅:
-
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 a bunch of potential delimiter characters, in contrast totokenizeToStringArray(java.lang.String, java.lang.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 a bunch of potential delimiter characters, in contrast totokenizeToStringArray(java.lang.String, java.lang.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
Delete any character in a givenString.- 参数:
inString- the originalStringcharsToDelete- a set of characters to delete. E.g. "az\n" will delete 'a's, 'z's and new lines.- 返回:
- the resulting
String
-
replace
Replace all occurrences of a substring within a string with another string.- 参数:
inString-Stringto examineoldPattern-Stringto replacenewPattern-Stringto insert- 返回:
- a
Stringwith the replacements
-
applyRelativePath
Apply the given relative path to the given Java resource path, assuming standard Java folder separation (i.e. "/" separators).- 参数:
path- the path to start from (usually a full file path)relativePath- the relative path to apply (relative to the full file path above)- 返回:
- the full file path that results from applying the relative path
-
getFilename
Extract the filename from the given Java resource path, e.g."myPath/myFile.txt" → "myFile.txt".- 参数:
path- the file path (maybenull)- 返回:
- the extracted filename, or
nullif none
-
capitalize
Capitalize aString, changing the first letter to upper case as perCharacter.toUpperCase(char). No other letters are changed.- 参数:
str- theStringto capitalize- 返回:
- the capitalized
String
-