Strings
Operations on String that are null
safe.
- Since
3.0
Value members
Concrete methods
Capitalizes a String changing the first letter to title case as per
[[Character#toTitleCase(char)]]
. No other letters are changed.
For a word based algorithm, see returns null
.
Capitalizes a String changing the first letter to title case as per
[[Character#toTitleCase(char)]]
. No other letters are changed.
For a word based algorithm, see returns null
.
capitalize(null) = null
capitalize("") = ""
capitalize("cat") = "Cat"
capitalize("cAt") = "CAt"
- Value Params
- str
the String to capitalize, may be null
- Returns
the capitalized String, { @code null} if null String input
- See also
#uncapitalize(String)
- Since
2.0
Checks if CharSequence contains a search CharSequence, handling null
. This method uses
[[String#indexOf(String)]]
if possible.
A null
CharSequence will return false
.
Checks if CharSequence contains a search CharSequence, handling null
. This method uses
[[String#indexOf(String)]]
if possible.
A null
CharSequence will return false
.
contains(null, *) = false
contains(*, null) = false
contains("", "") = true
contains("abc", "") = true
contains("abc", "a") = true
contains("abc", "z") = false
- Value Params
- searchSeq
the CharSequence to find, may be null
- seq
the CharSequence to check, may be null
- Returns
true if the CharSequence contains the search CharSequence, false if not or { @code null} string input
Checks if CharSequence contains a search character, handling null
. This method uses
[[String#indexOf(int)]]
if possible.
A null
or empty ("") CharSequence will return false
.
Checks if CharSequence contains a search character, handling null
. This method uses
[[String#indexOf(int)]]
if possible.
A null
or empty ("") CharSequence will return false
.
contains(null, *) = false
contains("", *) = false
contains("abc", 'a') = true
contains("abc", 'z') = false
- Value Params
- searchChar
the character to find
- seq
the CharSequence to check, may be null
- Returns
true if the CharSequence contains the search character, false if not or { @code null} string input
- Since
2.0
count char in host string
count char in host string
- Value Params
- charactor
a char.
- host
String object.
- Returns
a int.
count inner string in host string
count inner string in host string
- Value Params
- host
a String object.
- searchStr
a String object.
- Returns
a int.
Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or
null
, the value of defaultStr
.
Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or
null
, the value of defaultStr
.
replace [bigen,end] [1...end] with givenStr 可以使用StringBuilder的replace方法替换该方法
replace [bigen,end] [1...end] with givenStr 可以使用StringBuilder的replace方法替换该方法
- Value Params
- beginAt
a int.
- contnets
a String object.
- endAt
a int.
- str
a String object.
- Returns
a String object.
intersectSeq.
intersectSeq.
- Value Params
- first
a String object.
- second
a String object.
- Returns
a String object.
返回一个新的逗号相隔字符串,实现其中的单词a-b的功能
返回一个新的逗号相隔字符串,实现其中的单词a-b的功能
- Value Params
- delimiter
a String object.
- first
a String object.
- second
a String object.
- Returns
a String object.
Checks if a CharSequence is whitespace, empty ("") or null.
Checks if a CharSequence is whitespace, empty ("") or null.
isBlank(null) = true
isBlank("") = true
isBlank(" ") = true
isBlank("bob") = false
isBlank(" bob ") = false
- Value Params
- cs
the CharSequence to check, may be null
- Returns
{ @code true} if the CharSequence is null, empty or whitespace
- Since
3.0
Returns true is cs is null or cs.length equals 0.
Returns true is cs is null or cs.length equals 0.
判断两个","逗号相隔的字符串中的单词是否完全等同.
判断两个","逗号相隔的字符串中的单词是否完全等同.
- Value Params
- delimiter
a String object.
- first
a String object.
- second
a String object.
- Returns
a boolean.
Checks if a CharSequence is not empty (""), not null and not whitespace only.
Checks if a CharSequence is not empty (""), not null and not whitespace only.
isNotBlank(null) = false
isNotBlank("") = false
isNotBlank(" ") = false
isNotBlank("bob") = true
isNotBlank(" bob ") = true
- Value Params
- cs
the CharSequence to check, may be null
- Returns
{ @code true} if the CharSequence is not empty and not null and not whitespace
- Since
3.0
将数组中的字符串,用delimiter串接起来.
首尾不加delimiter
将数组中的字符串,用delimiter串接起来.
首尾不加delimiter
- Value Params
- delimiter
a String object.
- seq
an array of String objects.
- Returns
a String object.
保持逗号分隔的各个单词都是唯一的。并且按照原来的顺序存放。
保持逗号分隔的各个单词都是唯一的。并且按照原来的顺序存放。
- Value Params
- keyString
a String object.
- Returns
a String object.
Left pad a String with a specified character.
Pad to a size of size
.
Left pad a String with a specified character.
Pad to a size of size
.
leftPad(null, *, *) = null
leftPad("", 3, 'z') = "zzz"
leftPad("bat", 3, 'z') = "bat"
leftPad("bat", 5, 'z') = "zzbat"
leftPad("bat", 1, 'z') = "bat"
leftPad("bat", -1, 'z') = "bat"
- Value Params
- padChar
the character to pad with
- size
the size to pad to
- str
the String to pad out, may be null
- Returns
left padded String or original String if no padding is necessary, { @code null} if null String input
- Since
3.0
mergeSeq.
mergeSeq.
- Value Params
- first
a String object.
- second
a String object.
- Returns
a String object.
将两个用delimiter串起来的字符串,合并成新的串,重复的"单词"只出现一次.
如果第一个字符串以delimiter开头,第二个字符串以delimiter结尾,
合并后的字符串仍以delimiter开头和结尾.
将两个用delimiter串起来的字符串,合并成新的串,重复的"单词"只出现一次.
如果第一个字符串以delimiter开头,第二个字符串以delimiter结尾,
合并后的字符串仍以delimiter开头和结尾.
mergeSeq(",1,2,", "") = ",1,2,"; mergeSeq(",1,2,", null) = ",1,2,"; mergeSeq("1,2", "3") = "1,2,3"; mergeSeq("1,2", "3,") = "1,2,3,"; mergeSeq(",1,2", "3,") = ",1,2,3,"; mergeSeq(",1,2,", ",3,") = ",1,2,3,";
- Value Params
- delimiter
a String object.
- first
a String object.
- second
a String object.
- Returns
a String object.
Removes all occurrences of a character from within the source string.
A null
source string will return null
. An empty ("") source string will return
the empty string.
Removes all occurrences of a character from within the source string.
A null
source string will return null
. An empty ("") source string will return
the empty string.
StringUtils.remove(null, *) = null
StringUtils.remove("", *) = ""
StringUtils.remove("queued", 'u') = "qeed"
StringUtils.remove("queued", 'z') = "queued"
- Value Params
- remove
the char to search for and remove, may be null
- str
the source String to search, may be null
- Returns
the substring with the char removed if found, { @code null} if null String input
removeWord.
removeWord.
- Value Params
- host
a String object.
- word
a String object.
- Returns
a String object.
removeWord.
removeWord.
- Value Params
- delimiter
a String object.
- host
a String object.
- word
a String object.
- Returns
a String object.
Returns padding using the specified delimiter repeated to a given length.
Returns padding using the specified delimiter repeated to a given length.
repeat(0, 'e') = ""
repeat(3, 'e') = "eee"
repeat(-2, 'e') = ""
- Value Params
- ch
character to repeat
- repeat
number of times to repeat char, negative treated as zero
- Returns
String with repeated character
- See also
#repeat(String, int)
Repeat a String repeat
times to form a new String.
Repeat a String repeat
times to form a new String.
repeat(null, 2) = null
repeat("", 0) = ""
repeat("", 2) = ""
repeat("a", 3) = "aaa"
repeat("ab", 2) = "abab"
repeat("a", -2) = ""
- Value Params
- repeat
number of times to repeat str, negative treated as zero
- str
the String to repeat, may be null
- Returns
a new String consisting of the original String repeated, { @code null} if null String input
- Since
3.0
Replaces all occurrences of a String within another String.
A null
reference passed to this method is a no-op.
Replaces all occurrences of a String within another String.
A null
reference passed to this method is a no-op.
replace(null, *, *) = null
replace("", *, *) = ""
replace("any", null, *) = "any"
replace("any", *, null) = "any"
replace("any", "", *) = "any"
replace("aba", "a", null) = "aba"
replace("aba", "a", "") = "b"
replace("aba", "a", "z") = "zbz"
- Value Params
- replacement
the String to replace it with, may be null
- searchString
the String to search for, may be null
- text
text to search and replace in, may be null
- Returns
the text with any replacements processed, { @code null} if null String input
Right pad a String with a specified character.
The String is padded to the size of size
.
Right pad a String with a specified character.
The String is padded to the size of size
.
rightPad(null, *, *) = null
rightPad("", 3, 'z') = "zzz"
rightPad("bat", 3, 'z') = "bat"
rightPad("bat", 5, 'z') = "batzz"
rightPad("bat", 1, 'z') = "bat"
rightPad("bat", -1, 'z') = "bat"
- Value Params
- padChar
the character to pad with
- size
the size to pad to
- str
the String to pad out, may be null
- Returns
right padded String or original String if no padding is necessary, { @code null} if null String input
- Since
3.0
Splits the provided text into an array, separator specified. This is an alternative to using
StringTokenizer.
A null
input String returns null
.
Splits the provided text into an array, separator specified. This is an alternative to using
StringTokenizer.
A null
input String returns null
.
split(null, *) = null
split("", *) = []
split("a.b.c", '.') = ["a", "b", "c"]
split("a..b.c", '.') = ["a", "b", "c"]
split("a:b:c", '.') = ["a:b:c"]
split("a b c", ' ') = ["a", "b", "c"]
split with separators
split with separators
- Value Params
- separatorChars
an array of char.
- target
a String object.
- Returns
an array of String objects.
Splits the provided text into an array, separators specified. This is an alternative to using
StringTokenizer.
A null
input String returns null
. A null
separatorChars splits on
whitespace.
Splits the provided text into an array, separators specified. This is an alternative to using
StringTokenizer.
A null
input String returns null
. A null
separatorChars splits on
whitespace.
split(null, *) = null
split("", *) = []
split("abc def", null) = ["abc", "def"]
split("abc def", " ") = ["abc", "def"]
split("abc def", " ") = ["abc", "def"]
split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
将1-2,3,4-9之类的序列拆分成数组
将1-2,3,4-9之类的序列拆分成数组
- Value Params
- numSeq
a String object.
- Returns
an array of Int objects.
Strips any of a set of characters from the end of a String.
Strips any of a set of characters from the end of a String.
A null
input String returns null
.
An empty string ("") input returns the empty string.
If the stripChars String is null
, whitespace is
stripped as defined by [[Character#isWhitespace(char)]]
.
stripEnd(null, *) = null
stripEnd("", *) = ""
stripEnd("abc", "") = "abc"
stripEnd(*, null) = *
stripEnd(" abcyx", "xyz") = " abc"
- Value Params
- str
the String to remove characters from, may be null
- stripChars
the characters to remove, null treated as whitespace
- Returns
the stripped String,
null
if null String input
Gets a substring from the specified String avoiding exceptions.
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start/end n
characters from the end of the
String.
The returned substring starts with the character in the start
position and ends before
the end
position. All position counting is zero-based -- i.e., to start at the
beginning of the string use start = 0
. Negative start and end positions can be used to
specify offsets relative to the end of the String.
If start
is not strictly to the left of end
, "" is returned.
substring(null, *, *) = null
substring("", * , *) = "";
substring("abc", 0, 2) = "ab"
substring("abc", 2, 0) = ""
substring("abc", 2, 4) = "c"
substring("abc", 4, 6) = ""
substring("abc", 2, 2) = ""
substring("abc", -2, -1) = "b"
substring("abc", -4, 2) = "ab"
- Value Params
- endIndex
the position to end at (exclusive), negative means count back from the end of the String by this many characters
- startIndex
the position to start from, negative means count back from the end of the String by this many characters
- str
the String to get the substring from, may be null
- Returns
substring from start position to end position, { @code null} if null String input
Gets the substring after the first occurrence of a separator. The separator is not returned.
A null
string input will return null
. An empty ("") string input will return
the empty string. A null
separator will return the empty string if the input string is
not null
.
If nothing is found, the empty string is returned.
Gets the substring after the first occurrence of a separator. The separator is not returned.
A null
string input will return null
. An empty ("") string input will return
the empty string. A null
separator will return the empty string if the input string is
not null
.
If nothing is found, the empty string is returned.
substringAfter(null, *) = null
substringAfter("", *) = ""
substringAfter(*, null) = ""
substringAfter("abc", "a") = "bc"
substringAfter("abcba", "b") = "cba"
substringAfter("abc", "c") = ""
substringAfter("abc", "d") = ""
substringAfter("abc", "") = "abc"
- Value Params
- separator
the String to search for, may be null
- str
the String to get a substring from, may be null
- Returns
the substring after the first occurrence of the separator, { @code null} if null String input
- Since
2.0
Gets the substring after the last occurrence of a separator. The separator is not returned.
A null
string input will return null
. An empty ("") string input will return
the empty string. An empty or null
separator will return the empty string if the input
string is not null
.
If nothing is found, the empty string is returned.
Gets the substring after the last occurrence of a separator. The separator is not returned.
A null
string input will return null
. An empty ("") string input will return
the empty string. An empty or null
separator will return the empty string if the input
string is not null
.
If nothing is found, the empty string is returned.
substringAfterLast(null, *) = null
substringAfterLast("", *) = ""
substringAfterLast(*, "") = ""
substringAfterLast(*, null) = ""
substringAfterLast("abc", "a") = "bc"
substringAfterLast("abcba", "b") = "a"
substringAfterLast("abc", "c") = ""
substringAfterLast("a", "a") = ""
substringAfterLast("a", "z") = ""
- Value Params
- separator
the String to search for, may be null
- str
the String to get a substring from, may be null
- Returns
the substring after the last occurrence of the separator, { @code null} if null String input
- Since
3.0
Gets the substring before the first occurrence of a separator. The separator is not returned.
A null
string input will return null
. An empty ("") string input will return
the empty string. A null
separator will return the input string.
If nothing is found, the string input is returned.
Gets the substring before the first occurrence of a separator. The separator is not returned.
A null
string input will return null
. An empty ("") string input will return
the empty string. A null
separator will return the input string.
If nothing is found, the string input is returned.
substringBefore(null, *) = null
substringBefore("", *) = ""
substringBefore("abc", "a") = ""
substringBefore("abcba", "b") = "a"
substringBefore("abc", "c") = "ab"
substringBefore("abc", "d") = "abc"
substringBefore("abc", "") = ""
substringBefore("abc", null) = "abc"
- Value Params
- separator
the String to search for, may be null
- str
the String to get a substring from, may be null
- Returns
the substring before the first occurrence of the separator, { @code null} if null String input
- Since
2.0
Gets the substring before the last occurrence of a separator. The separator is not returned.
A null
string input will return null
. An empty ("") string input will return
the empty string. An empty or null
separator will return the input string.
If nothing is found, the string input is returned.
Gets the substring before the last occurrence of a separator. The separator is not returned.
A null
string input will return null
. An empty ("") string input will return
the empty string. An empty or null
separator will return the input string.
If nothing is found, the string input is returned.
substringBeforeLast(null, *) = null
substringBeforeLast("", *) = ""
substringBeforeLast("abcba", "b") = "abc"
substringBeforeLast("abc", "c") = "ab"
substringBeforeLast("a", "a") = ""
substringBeforeLast("a", "z") = "a"
substringBeforeLast("a", null) = "a"
substringBeforeLast("a", "") = "a"
- Value Params
- separator
the String to search for, may be null
- str
the String to get a substring from, may be null
- Returns
the substring before the last occurrence of the separator, { @code null} if null String input
- Since
3.0
Gets the String that is nested in between two Strings. Only the first match is returned.
A null
input String returns null
. A null
open/close returns
null
(no match). An empty ("") open and close returns an empty string.
Gets the String that is nested in between two Strings. Only the first match is returned.
A null
input String returns null
. A null
open/close returns
null
(no match). An empty ("") open and close returns an empty string.
substringBetween("wx[b]yz", "[", "]") = "b"
substringBetween(null, *, *) = null
substringBetween(*, null, *) = null
substringBetween(*, *, null) = null
substringBetween("", "", "") = ""
substringBetween("", "", "]") = null
substringBetween("", "[", "]") = null
substringBetween("yabcz", "", "") = ""
substringBetween("yabcz", "y", "z") = "abc"
substringBetween("yabczyabcz", "y", "z") = "abc"
- Value Params
- close
the String after the substring, may be null
- open
the String before the substring, may be null
- str
the String containing the substring, may be null
- Returns
the substring, { @code null} if no match
- Since
3.0
subtractSeq.
subtractSeq.
- Value Params
- first
a String object.
- second
a String object.
- Returns
a String object.
Removes control characters (char <= 32) from both ends of this String, handling null
by returning null
.
The String is trimmed using [[String#trim()]]
. Trim removes start and end characters <=
32.
Removes control characters (char <= 32) from both ends of this String, handling null
by returning null
.
The String is trimmed using [[String#trim()]]
. Trim removes start and end characters <=
32.
trim(null) = null
trim("") = ""
trim(" ") = ""
trim("abc") = "abc"
trim(" abc ") = "abc"
- Value Params
- str
the String to be trimmed, may be null
- Returns
the trimmed string, { @code null} if null String input
- Since
3.0
将驼峰表示法转换为下划线小写表示
将驼峰表示法转换为下划线小写表示
- Value Params
- lowercase
a boolean.
- seperator
a char.
- str
a String object.
- Returns
a String object.
Uncapitalizes a String changing the first letter to title case as per
java.lang.Character#toLowerCase. No other letters are changed.
For a word based algorithm, see String returns null
.
Uncapitalizes a String changing the first letter to title case as per
java.lang.Character#toLowerCase. No other letters are changed.
For a word based algorithm, see String returns null
.
uncapitalize(null) = null
uncapitalize("") = ""
uncapitalize("Cat") = "cat"
uncapitalize("CAT") = "cAT"
- Value Params
- str
the String to uncapitalize, may be null
- Returns
the uncapitalized String, { @code null} if null String input
- See also
#capitalize(String)
- Since
3.0