|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectcom.baidu.driver4j.bns.StringUtils
public class StringUtils
String utility class.
| 字段摘要 | |
|---|---|
static String |
EMPTY
The empty String "". |
static String |
EMPTY_STRING
|
| 构造方法摘要 | |
|---|---|
StringUtils()
|
|
| 方法摘要 | |
|---|---|
static byte[] |
addAll(byte[] array1,
byte[] array2)
Adds all the elements of the given arrays into a new array. |
static String |
capitalize(String str)
Capitalizes a String changing the first letter to title case as per Character.toTitleCase(char). |
static byte[] |
clone(byte[] array)
Clones an array returning a typecast result and handling null. |
static boolean |
endsWith(String str,
String suffix)
Check if a String ends with a specified suffix. |
static boolean |
endsWithIgnoreCase(String str,
String suffix)
Case insensitive check if a String ends with a specified suffix. |
static String |
escapeBytes(byte[] input)
Like #escapeBytes(ByteString), but used for byte array. |
static String |
escapeJava(String str)
Escapes the characters in a String using Java String rules. |
static void |
escapeJava(Writer out,
String str)
Escapes the characters in a String using Java String rules to a Writer. |
static boolean |
isEmpty(String str)
Checks if a String is empty ("") or null. |
static String |
join(Iterator iterator,
char separator)
Joins the elements of the provided Iterator into
a single String containing the provided elements. |
static String |
join(Object[] array)
Joins the elements of the provided array into a single String containing the provided list of elements. |
static String |
join(Object[] array,
char separator)
Joins the elements of the provided array into a single String containing the provided list of elements. |
static String |
join(Object[] array,
char separator,
int startIndex,
int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements. |
static String |
join(Object[] array,
String separator)
Joins the elements of the provided array into a single String containing the provided list of elements. |
static String |
join(Object[] array,
String separator,
int startIndex,
int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements. |
static String |
removeEnd(String str,
String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string. |
static String |
removeEndIgnoreCase(String str,
String remove)
Case insensitive removal of a substring if it is at the end of a source string, otherwise returns the source string. |
static String |
removeStart(String str,
String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string. |
static String |
removeStartIgnoreCase(String str,
String remove)
Case insensitive removal of a substring if it is at the begining of a source string, otherwise returns the source string. |
static String[] |
split(String str)
Splits the provided text into an array, using whitespace as the separator. |
static String[] |
split(String str,
char separatorChar)
Splits the provided text into an array, separator specified. |
static String[] |
split(String str,
String separatorChars)
Splits the provided text into an array, separators specified. |
static String[] |
split(String str,
String separatorChars,
int max)
Splits the provided text into an array with a maximum length, separators specified. |
static String[] |
splitByWholeSeparator(String str,
String separator)
Splits the provided text into an array, separator string specified. |
static String[] |
splitByWholeSeparator(String str,
String separator,
int max)
Splits the provided text into an array, separator string specified. |
static String[] |
splitByWholeSeparatorPreserveAllTokens(String str,
String separator)
Splits the provided text into an array, separator string specified. |
static String[] |
splitByWholeSeparatorPreserveAllTokens(String str,
String separator,
int max)
Splits the provided text into an array, separator string specified. |
static boolean |
startsWith(String str,
String prefix)
Check if a String starts with a specified prefix. |
static boolean |
startsWithIgnoreCase(String str,
String prefix)
Case insensitive check if a String starts with a specified prefix. |
static int |
stringToInt(String str,
int defaultValue)
已过时。 Use toInt(String, int) This method will be removed in Commons Lang 3.0 |
static String |
substringAfterLast(String str,
String separator)
Gets the substring after the last occurrence of a separator. |
static String |
substringBefore(String str,
String separator)
Gets the substring before the first occurrence of a separator. |
static String |
substringBeforeLast(String str,
String separator)
Gets the substring before the last occurrence of a separator. |
static int |
toInt(String str)
Convert a String to an int, returning zero if the conversion fails. |
static int |
toInt(String str,
int defaultValue)
Convert a String to an int, returning a default value if the conversion fails. |
static long |
toLong(String str)
Convert a String to an long, returning a default value if the conversion fails. |
static long |
toLong(String str,
long defaultValue)
Convert a String to an long, returning a default value if the conversion fails. |
static String |
toString(Object obj)
Gets the toString of an Object returning
an empty string ("") if null input. |
static String |
trimToEmpty(String str)
Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null. |
static String |
unescapeJava(String str)
Unescapes any Java literals found in the String. |
static void |
unescapeJava(Writer out,
String str)
Unescapes any Java literals found in the String to a Writer. |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 字段详细信息 |
|---|
public static final String EMPTY_STRING
public static final String EMPTY
"".
| 构造方法详细信息 |
|---|
public StringUtils()
| 方法详细信息 |
|---|
public static boolean endsWith(String str,
String suffix)
Check if a String ends with a specified suffix.
nulls are handled without exceptions. Two null
references are considered to be equal. The comparison is case sensitive.
StringUtils.endsWith(null, null) = true
StringUtils.endsWith(null, "abcdef") = false
StringUtils.endsWith("def", null) = false
StringUtils.endsWith("def", "abcdef") = true
StringUtils.endsWith("def", "ABCDEF") = false
str - the String to check, may be nullsuffix - the suffix to find, may be null
true if the String ends with the suffix, case
sensitive, or both nullString.endsWith(String)
public static boolean endsWithIgnoreCase(String str,
String suffix)
Case insensitive check if a String ends with a specified suffix.
nulls are handled without exceptions. Two null
references are considered to be equal. The comparison is case
insensitive.
StringUtils.endsWithIgnoreCase(null, null) = true
StringUtils.endsWithIgnoreCase(null, "abcdef") = false
StringUtils.endsWithIgnoreCase("def", null) = false
StringUtils.endsWithIgnoreCase("def", "abcdef") = true
StringUtils.endsWithIgnoreCase("def", "ABCDEF") = false
str - the String to check, may be nullsuffix - the suffix to find, may be null
true if the String ends with the suffix, case
insensitive, or both nullString.endsWith(String)
public static String removeEnd(String str,
String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null. An empty
("") source string will return the empty string. A null
search string will return the source string.
StringUtils.removeEnd(null, *) = null
StringUtils.removeEnd("", *) = ""
StringUtils.removeEnd(*, null) = *
StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com"
StringUtils.removeEnd("www.domain.com", ".com") = "www.domain"
StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeEnd("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for and remove, may be null
null
if null String input
public static String removeEndIgnoreCase(String str,
String remove)
Case insensitive removal of a substring if it is at the end of a source string, otherwise returns the source string.
A null source string will return null. An empty
("") source string will return the empty string. A null
search string will return the source string.
StringUtils.removeEnd(null, *) = null
StringUtils.removeEnd("", *) = ""
StringUtils.removeEnd(*, null) = *
StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com."
StringUtils.removeEnd("www.domain.com", ".com") = "www.domain"
StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeEnd("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for (case insensitive) and remove, may be
null
null
if null String inputpublic static boolean isEmpty(String str)
Checks if a String is empty ("") or null.
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().
str - the String to check, may be null
true if the String is empty or null
public static String removeStart(String str,
String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
A null source string will return null. An empty
("") source string will return the empty string. A null
search string will return the source string.
StringUtils.removeStart(null, *) = null
StringUtils.removeStart("", *) = ""
StringUtils.removeStart(*, null) = *
StringUtils.removeStart("www.domain.com", "www.") = "domain.com"
StringUtils.removeStart("domain.com", "www.") = "domain.com"
StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeStart("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for and remove, may be null
null
if null String input
public static String removeStartIgnoreCase(String str,
String remove)
Case insensitive removal of a substring if it is at the begining of a source string, otherwise returns the source string.
A null source string will return null. An empty
("") source string will return the empty string. A null
search string will return the source string.
StringUtils.removeStartIgnoreCase(null, *) = null
StringUtils.removeStartIgnoreCase("", *) = ""
StringUtils.removeStartIgnoreCase(*, null) = *
StringUtils.removeStartIgnoreCase("www.domain.com", "www.") = "domain.com"
StringUtils.removeStartIgnoreCase("www.domain.com", "WWW.") = "domain.com"
StringUtils.removeStartIgnoreCase("domain.com", "www.") = "domain.com"
StringUtils.removeStartIgnoreCase("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeStartIgnoreCase("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for (case insensitive) and remove, may be
null
null
if null String input
public static boolean startsWith(String str,
String prefix)
Check if a String starts with a specified prefix.
nulls are handled without exceptions. Two null
references are considered to be equal. The comparison is case sensitive.
StringUtils.startsWith(null, null) = true
StringUtils.startsWith(null, "abcdef") = false
StringUtils.startsWith("abc", null) = false
StringUtils.startsWith("abc", "abcdef") = true
StringUtils.startsWith("abc", "ABCDEF") = false
str - the String to check, may be nullprefix - the prefix to find, may be null
true if the String starts with the prefix, case
sensitive, or both nullString.startsWith(String)
public static boolean startsWithIgnoreCase(String str,
String prefix)
Case insensitive check if a String starts with a specified prefix.
nulls are handled without exceptions. Two null
references are considered to be equal. The comparison is case
insensitive.
StringUtils.startsWithIgnoreCase(null, null) = true
StringUtils.startsWithIgnoreCase(null, "abcdef") = false
StringUtils.startsWithIgnoreCase("abc", null) = false
StringUtils.startsWithIgnoreCase("abc", "abcdef") = true
StringUtils.startsWithIgnoreCase("abc", "ABCDEF") = true
str - the String to check, may be nullprefix - the prefix to find, may be null
true if the String starts with the prefix, case
insensitive, or both nullString.startsWith(String)
public static String substringBefore(String str,
String separator)
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.
StringUtils.substringBefore(null, *) = null
StringUtils.substringBefore("", *) = ""
StringUtils.substringBefore("abc", "a") = ""
StringUtils.substringBefore("abcba", "b") = "a"
StringUtils.substringBefore("abc", "c") = "ab"
StringUtils.substringBefore("abc", "d") = "abc"
StringUtils.substringBefore("abc", "") = ""
StringUtils.substringBefore("abc", null) = "abc"
str - the String to get a substring from, may be nullseparator - the String to search for, may be null
null if null String input
public static String substringBeforeLast(String str,
String separator)
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.
StringUtils.substringBeforeLast(null, *) = null
StringUtils.substringBeforeLast("", *) = ""
StringUtils.substringBeforeLast("abcba", "b") = "abc"
StringUtils.substringBeforeLast("abc", "c") = "ab"
StringUtils.substringBeforeLast("a", "a") = ""
StringUtils.substringBeforeLast("a", "z") = "a"
StringUtils.substringBeforeLast("a", null) = "a"
StringUtils.substringBeforeLast("a", "") = "a"
str - the String to get a substring from, may be nullseparator - the String to search for, may be null
null if null String input
public static String substringAfterLast(String str,
String separator)
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.
StringUtils.substringAfterLast(null, *) = null
StringUtils.substringAfterLast("", *) = ""
StringUtils.substringAfterLast(*, "") = ""
StringUtils.substringAfterLast(*, null) = ""
StringUtils.substringAfterLast("abc", "a") = "bc"
StringUtils.substringAfterLast("abcba", "b") = "a"
StringUtils.substringAfterLast("abc", "c") = ""
StringUtils.substringAfterLast("a", "a") = ""
StringUtils.substringAfterLast("a", "z") = ""
str - the String to get a substring from, may be nullseparator - the String to search for, may be null
null if null String inputpublic static String capitalize(String str)
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 WordUtils#capitalize(String).
A null input String returns null.
StringUtils.capitalize(null) = null
StringUtils.capitalize("") = ""
StringUtils.capitalize("cat") = "Cat"
StringUtils.capitalize("cAt") = "CAt"
str - the String to capitalize, may be null
null if null String inputWordUtils#capitalize(String),
#uncapitalize(String)public static String escapeJava(String str)
Escapes the characters in a String using Java String rules.
Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
So a tab becomes the characters '\\' and 't'.
The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.
Example:
input string: He didn't say, "Stop!" output string: He didn't say, \"Stop!\"
str - String to escape values in, may be null
null if null string input
public static void escapeJava(Writer out,
String str)
throws IOException
Escapes the characters in a String using Java String rules to a Writer.
A null string input has no effect.
out - Writer to write escaped string intostr - String to escape values in, may be null
IllegalArgumentException - if the Writer is null
IOException - if error occurs on underlying WriterescapeJava(java.lang.String)public static String unescapeJava(String str)
Unescapes any Java literals found in the String. For example, it will turn a sequence of
'\' and 'n' into a newline character, unless the '\' is preceded by
another '\'.
str - the String to unescape, may be null
String, null if null string input
public static void unescapeJava(Writer out,
String str)
throws IOException
Unescapes any Java literals found in the String to a Writer.
For example, it will turn a sequence of '\' and 'n' into a newline character, unless
the '\' is preceded by another '\'.
A null string input has no effect.
out - the Writer used to output unescaped charactersstr - the String to unescape, may be null
IllegalArgumentException - if the Writer is null
IOException - if error occurs on underlying Writerpublic static 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 null
null if null String input
public static 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 delimiter
null if null String input
public static 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 whitespace
null if null String input
public static 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 de fg", null, 0) = ["ab", "cd", "ef"]
StringUtils.split("ab de fg", 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 limit
null if null String input
public static 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 whitespace
null if null String was input
public static 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 input
public static 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 whitespace
null if null String was input
public static 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 String escapeBytes(byte[] input)
#escapeBytes(ByteString), but used for byte array.
public static int toInt(String str)
Convert a String to an int, returning zero if the conversion fails.
If the string is null, zero is returned.
NumberUtils.toInt(null) = 0
NumberUtils.toInt("") = 0
NumberUtils.toInt("1") = 1
str - the string to convert, may be null
zero if conversion fails
public static int stringToInt(String str,
int defaultValue)
toInt(String, int) This method will be removed in Commons Lang 3.0
Convert a String to an int, returning a default value if the conversion fails.
If the string is null, the default value is returned.
NumberUtils.stringToInt(null, 1) = 1
NumberUtils.stringToInt("", 1) = 1
NumberUtils.stringToInt("1", 0) = 1
str - the string to convert, may be nulldefaultValue - the default value
public static int toInt(String str,
int defaultValue)
Convert a String to an int, returning a default value if the conversion fails.
If the string is null, the default value is returned.
NumberUtils.toInt(null, 1) = 1
NumberUtils.toInt("", 1) = 1
NumberUtils.toInt("1", 0) = 1
str - the string to convert, may be nulldefaultValue - the default value
public static long toLong(String str)
Convert a String to an long, returning a default value if the conversion fails.
If the string is null, the default value is returned.
NumberUtils.toLong(null) = 0
NumberUtils.toLong("") = 0
NumberUtils.toLong("1") = 1
str - the string to convert, may be null
public static long toLong(String str,
long defaultValue)
Convert a String to an long, returning a default value if the conversion fails.
If the string is null, the default value is returned.
NumberUtils.toLong(null, 1) = 1
NumberUtils.toLong("", 1) = 1
NumberUtils.toLong("1", 0) = 1
str - the string to convert, may be nulldefaultValue - the default value
public static String trimToEmpty(String str)
Removes control characters (char <= 32) from both
ends of this String returning an empty String ("") if the String
is empty ("") after the trim or if it is null.
The String is trimmed using String.trim().
Trim removes start and end characters <= 32.
To strip whitespace use #stripToEmpty(String).
StringUtils.trimToEmpty(null) = ""
StringUtils.trimToEmpty("") = ""
StringUtils.trimToEmpty(" ") = ""
StringUtils.trimToEmpty("abc") = "abc"
StringUtils.trimToEmpty(" abc ") = "abc"
str - the String to be trimmed, may be null
null inputpublic static String join(Object[] array)
Joins the elements of the provided array into a single String containing the provided list of elements.
No separator is added to the joined String. Null objects or empty strings within the array are represented by empty strings.
StringUtils.join(null) = null StringUtils.join([]) = "" StringUtils.join([null]) = "" StringUtils.join(["a", "b", "c"]) = "abc" StringUtils.join([null, "", "a"]) = "a"
array - the array of values to join together, may be null
null if null array input
public static String join(Object[] array,
char separator)
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.
StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join(["a", "b", "c"], ';') = "a;b;c" StringUtils.join(["a", "b", "c"], null) = "abc" StringUtils.join([null, "", "a"], ';') = ";;a"
array - the array of values to join together, may be nullseparator - the separator character to use
null if null array input
public static String join(Object[] array,
char separator,
int startIndex,
int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.
StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join(["a", "b", "c"], ';') = "a;b;c" StringUtils.join(["a", "b", "c"], null) = "abc" StringUtils.join([null, "", "a"], ';') = ";;a"
array - the array of values to join together, may be nullseparator - the separator character to usestartIndex - the first index to start joining from. It is
an error to pass in an end index past the end of the arrayendIndex - the index to stop joining from (exclusive). It is
an error to pass in an end index past the end of the array
null if null array input
public static String join(Object[] array,
String separator)
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list.
A null separator is the same as an empty String ("").
Null objects or empty strings within the array are represented by
empty strings.
StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join(["a", "b", "c"], "--") = "a--b--c" StringUtils.join(["a", "b", "c"], null) = "abc" StringUtils.join(["a", "b", "c"], "") = "abc" StringUtils.join([null, "", "a"], ',') = ",,a"
array - the array of values to join together, may be nullseparator - the separator character to use, null treated as ""
null if null array input
public static String join(Object[] array,
String separator,
int startIndex,
int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list.
A null separator is the same as an empty String ("").
Null objects or empty strings within the array are represented by
empty strings.
StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join(["a", "b", "c"], "--") = "a--b--c" StringUtils.join(["a", "b", "c"], null) = "abc" StringUtils.join(["a", "b", "c"], "") = "abc" StringUtils.join([null, "", "a"], ',') = ",,a"
array - the array of values to join together, may be nullseparator - the separator character to use, null treated as ""startIndex - the first index to start joining from. It is
an error to pass in an end index past the end of the arrayendIndex - the index to stop joining from (exclusive). It is
an error to pass in an end index past the end of the array
null if null array input
public static String join(Iterator iterator,
char separator)
Joins the elements of the provided Iterator into
a single String containing the provided elements.
No delimiter is added before or after the list. Null objects or empty strings within the iteration are represented by empty strings.
See the examples here: join(Object[],char).
iterator - the Iterator of values to join together, may be nullseparator - the separator character to use
null if null iterator inputpublic static String toString(Object obj)
Gets the toString of an Object returning
an empty string ("") if null input.
ObjectUtils.toString(null) = ""
ObjectUtils.toString("") = ""
ObjectUtils.toString("bat") = "bat"
ObjectUtils.toString(Boolean.TRUE) = "true"
obj - the Object to toString, may be null
null inputStringUtils#defaultString(String),
String.valueOf(Object)
public static byte[] addAll(byte[] array1,
byte[] array2)
Adds all the elements of the given arrays into a new array.
The new array contains all of the element of array1 followed
by all of the elements array2. When an array is returned, it is always
a new array.
ArrayUtils.addAll(array1, null) = cloned copy of array1 ArrayUtils.addAll(null, array2) = cloned copy of array2 ArrayUtils.addAll([], []) = []
array1 - the first array whose elements are added to the new array.array2 - the second array whose elements are added to the new array.
public static byte[] clone(byte[] array)
Clones an array returning a typecast result and handling
null.
This method returns null for a null input array.
array - the array to clone, may be null
null if null input
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||