com.baidu.driver4j.bns
类 StringUtils

java.lang.Object
  继承者 com.baidu.driver4j.bns.StringUtils

public class StringUtils
extends Object

String utility class.

从以下版本开始:
1.2.5
作者:
xiemalin

字段摘要
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
 

字段详细信息

EMPTY_STRING

public static final String EMPTY_STRING
另请参见:
常量字段值

EMPTY

public static final String EMPTY
The empty String "".

从以下版本开始:
2.0
另请参见:
常量字段值
构造方法详细信息

StringUtils

public StringUtils()
方法详细信息

endsWith

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 null
suffix - the suffix to find, may be null
返回:
true if the String ends with the suffix, case sensitive, or both null
从以下版本开始:
2.4
另请参见:
String.endsWith(String)

endsWithIgnoreCase

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 null
suffix - the suffix to find, may be null
返回:
true if the String ends with the suffix, case insensitive, or both null
从以下版本开始:
2.4
另请参见:
String.endsWith(String)

removeEnd

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 null
remove - the String to search for and remove, may be null
返回:
the substring with the string removed if found, null if null String input
从以下版本开始:
2.1

removeEndIgnoreCase

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 null
remove - the String to search for (case insensitive) and remove, may be null
返回:
the substring with the string removed if found, null if null String input
从以下版本开始:
2.4

isEmpty

public 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

removeStart

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 null
remove - the String to search for and remove, may be null
返回:
the substring with the string removed if found, null if null String input
从以下版本开始:
2.1

removeStartIgnoreCase

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 null
remove - the String to search for (case insensitive) and remove, may be null
返回:
the substring with the string removed if found, null if null String input
从以下版本开始:
2.4

startsWith

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 null
prefix - the prefix to find, may be null
返回:
true if the String starts with the prefix, case sensitive, or both null
从以下版本开始:
2.4
另请参见:
String.startsWith(String)

startsWithIgnoreCase

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 null
prefix - the prefix to find, may be null
返回:
true if the String starts with the prefix, case insensitive, or both null
从以下版本开始:
2.4
另请参见:
String.startsWith(String)

substringBefore

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 null
separator - the String to search for, may be null
返回:
the substring before the first occurrence of the separator, null if null String input
从以下版本开始:
2.0

substringBeforeLast

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 null
separator - the String to search for, may be null
返回:
the substring before the last occurrence of the separator, null if null String input
从以下版本开始:
2.0

substringAfterLast

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 null
separator - the String to search for, may be null
返回:
the substring after the last occurrence of the separator, null if null String input
从以下版本开始:
2.0

capitalize

public 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
返回:
the capitalized String, null if null String input
从以下版本开始:
2.0
另请参见:
WordUtils#capitalize(String), #uncapitalize(String)

escapeJava

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
返回:
String with escaped values, null if null string input

escapeJava

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 into
str - String to escape values in, may be null
抛出:
IllegalArgumentException - if the Writer is null
IOException - if error occurs on underlying Writer
另请参见:
escapeJava(java.lang.String)

unescapeJava

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
返回:
a new unescaped String, null if null string input

unescapeJava

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 characters
str - the String to unescape, may be null
抛出:
IllegalArgumentException - if the Writer is null
IOException - if error occurs on underlying Writer

split

public 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
返回:
an array of parsed Strings, null if null String input

split

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 null
separatorChar - the character used as the delimiter
返回:
an array of parsed Strings, null if null String input
从以下版本开始:
2.0

split

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 null
separatorChars - the characters used as the delimiters, null splits on whitespace
返回:
an array of parsed Strings, null if null String input

split

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 null
separatorChars - the characters used as the delimiters, null splits on whitespace
max - the maximum number of elements to include in the array. A zero or negative value implies no limit
返回:
an array of parsed Strings, null if null String input

splitByWholeSeparator

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 null
separator - String containing the String to be used as a delimiter, null splits on whitespace
返回:
an array of parsed Strings, null if null String was input

splitByWholeSeparator

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 null
separator - String containing the String to be used as a delimiter, null splits on whitespace
max - the maximum number of elements to include in the returned array. A zero or negative value implies no limit.
返回:
an array of parsed Strings, null if null String was input

splitByWholeSeparatorPreserveAllTokens

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 null
separator - String containing the String to be used as a delimiter, null splits on whitespace
返回:
an array of parsed Strings, null if null String was input
从以下版本开始:
2.4

splitByWholeSeparatorPreserveAllTokens

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 null
separator - String containing the String to be used as a delimiter, null splits on whitespace
max - the maximum number of elements to include in the returned array. A zero or negative value implies no limit.
返回:
an array of parsed Strings, null if null String was input
从以下版本开始:
2.4

escapeBytes

public static String escapeBytes(byte[] input)
Like #escapeBytes(ByteString), but used for byte array.


toInt

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
返回:
the int represented by the string, or zero if conversion fails
从以下版本开始:
2.1

stringToInt

public static int stringToInt(String str,
                              int defaultValue)
已过时。 Use 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 null
defaultValue - the default value
返回:
the int represented by the string, or the default if conversion fails

toInt

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 null
defaultValue - the default value
返回:
the int represented by the string, or the default if conversion fails
从以下版本开始:
2.1

toLong

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
返回:
the long represented by the string, or the default if conversion fails
从以下版本开始:
2.1

toLong

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 null
defaultValue - the default value
返回:
the long represented by the string, or the default if conversion fails
从以下版本开始:
2.1

trimToEmpty

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
返回:
the trimmed String, or an empty String if null input
从以下版本开始:
2.0

join

public 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
返回:
the joined String, null if null array input
从以下版本开始:
2.0

join

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 null
separator - the separator character to use
返回:
the joined String, null if null array input
从以下版本开始:
2.0

join

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 null
separator - the separator character to use
startIndex - the first index to start joining from. It is an error to pass in an end index past the end of the array
endIndex - the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array
返回:
the joined String, null if null array input
从以下版本开始:
2.0

join

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 null
separator - the separator character to use, null treated as ""
返回:
the joined String, null if null array input

join

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 null
separator - 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 array
endIndex - the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array
返回:
the joined String, null if null array input

join

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 null
separator - the separator character to use
返回:
the joined String, null if null iterator input
从以下版本开始:
2.0

toString

public 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
返回:
the passed in Object's toString, or nullStr if null input
从以下版本开始:
2.0
另请参见:
StringUtils#defaultString(String), String.valueOf(Object)

addAll

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.
返回:
The new byte[] array.
从以下版本开始:
2.1

clone

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
返回:
the cloned array, null if null input


Copyright © 2016. All rights reserved.