public class StringUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
StringUtils.StringFormatter<T> |
| Constructor and Description |
|---|
StringUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
equals(String str1,
String str2)
Compares two Strings, returning
true if they are equal. |
static boolean |
equalsIgnoreCase(String str1,
String str2)
Compares two Strings, returning
true if they are equal ignoring the case. |
static boolean |
isBlank(String str)
Checks if a String is whitespace, empty ("") or null.
|
static boolean |
isContainEmpty(String... args) |
static boolean |
isEmpty(String str)
Checks if a String is empty ("") or null.
|
static boolean |
isNumeric(String str)
Checks if the String contains only unicode digits.
|
static <T> String |
join(Collection<T> collection,
String separator) |
static <T> String |
join(Collection<T> collection,
String separator,
StringUtils.StringFormatter<T> formatter) |
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 String |
trim(String str)
Removes control characters (char <= 32) from both ends of this String, handling
null by returning
null. |
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 |
trimToNull(String str)
Removes control characters (char <= 32) from both ends of this String returning
null if the String is empty
("") after the trim or if it is null. |
public static final String EMPTY
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 nulltrue if the String is empty or nullpublic static boolean isContainEmpty(String... args)
public static boolean isBlank(String str)
Checks if a String is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
str - the String to check, may be nulltrue if the String is null, empty or whitespacepublic static String trimToNull(String str)
Removes control characters (char <= 32) from both ends of this String returning null 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
#stripToNull(String).
StringUtils.trimToNull(null) = null
StringUtils.trimToNull("") = null
StringUtils.trimToNull(" ") = null
StringUtils.trimToNull("abc") = "abc"
StringUtils.trimToNull(" abc ") = "abc"
str - the String to be trimmed, may be nullnull if only chars <= 32, empty or null String inputpublic 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 nullnull inputpublic static String trim(String str)
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. To strip whitespace use
#strip(String).
To trim your choice of characters, use the #strip(String, String) methods.
StringUtils.trim(null) = null
StringUtils.trim("") = ""
StringUtils.trim(" ") = ""
StringUtils.trim("abc") = "abc"
StringUtils.trim(" abc ") = "abc"
str - the String to be trimmed, may be nullnull if null String inputpublic static boolean equals(String str1, String str2)
Compares two Strings, returning true if they are equal.
nulls are handled without exceptions. Two null references are considered to be equal. The comparison
is case sensitive.
StringUtils.equals(null, null) = true
StringUtils.equals(null, "abc") = false
StringUtils.equals("abc", null) = false
StringUtils.equals("abc", "abc") = true
StringUtils.equals("abc", "ABC") = false
str1 - the first String, may be nullstr2 - the second String, may be nulltrue if the Strings are equal, case sensitive, or both nullString.equals(Object)public static boolean equalsIgnoreCase(String str1, String str2)
Compares two Strings, returning true if they are equal ignoring the case.
nulls are handled without exceptions. Two null references are considered equal. Comparison is case
insensitive.
StringUtils.equalsIgnoreCase(null, null) = true
StringUtils.equalsIgnoreCase(null, "abc") = false
StringUtils.equalsIgnoreCase("abc", null) = false
StringUtils.equalsIgnoreCase("abc", "abc") = true
StringUtils.equalsIgnoreCase("abc", "ABC") = true
str1 - the first String, may be nullstr2 - the second String, may be nulltrue if the Strings are equal, case insensitive, or both nullString.equalsIgnoreCase(String)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, "abc") = false
StringUtils.startsWith("abcdef", null) = false
StringUtils.startsWith("abcdef", "abc") = true
StringUtils.startsWith("ABCDEF", "abc") = false
str - the String to check, may be nullprefix - the prefix to find, may be nulltrue 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, "abc") = false
StringUtils.startsWithIgnoreCase("abcdef", null) = false
StringUtils.startsWithIgnoreCase("abcdef", "abc") = true
StringUtils.startsWithIgnoreCase("ABCDEF", "abc") = true
str - the String to check, may be nullprefix - the prefix to find, may be nulltrue if the String starts with the prefix, case insensitive, or both nullString.startsWith(String)public static boolean isNumeric(String str)
Checks if the String contains only unicode digits. A decimal point is not a unicode digit and returns false.
null will return false. An empty String (length()=0) will return true.
StringUtils.isNumeric(null) = false
StringUtils.isNumeric("") = true
StringUtils.isNumeric(" ") = false
StringUtils.isNumeric("123") = true
StringUtils.isNumeric("12 3") = false
StringUtils.isNumeric("ab2c") = false
StringUtils.isNumeric("12-3") = false
StringUtils.isNumeric("12.3") = false
str - the String to check, may be nulltrue if only contains digits, and is non-nullpublic static <T> String join(Collection<T> collection, String separator)
public static <T> String join(Collection<T> collection, String separator, StringUtils.StringFormatter<T> formatter)
Copyright © 2018 Ctrip, Inc.. All rights reserved.