public class StringUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
ALL
The string
"*". |
static String |
CONTEXT_SEP
The context path separator String
"/". |
static String |
DEFAULT
The string
"default". |
static String |
EMPTY
The empty String
"". |
static String[] |
EMPTY_STRING_ARRAY
空数组
|
static String |
FALSE
The string
"false". |
static String |
NULL
The string
"null". |
static String |
TRUE
The string
"true". |
| 构造器和说明 |
|---|
StringUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
defaultString(Object str)
Returns either the passed in String,
or if the String is
null, an empty String (""). |
static boolean |
equals(CharSequence s1,
CharSequence s2)
字符串是否相同
|
static boolean |
isBlank(CharSequence cs)
Checks if a CharSequence is whitespace, empty ("") or null.
|
static boolean |
isEmpty(CharSequence cs)
Checks if a CharSequence is empty ("") or null.
|
static boolean |
isNotBlank(CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
|
static boolean |
isNotEmpty(CharSequence cs)
Checks if a CharSequence is not empty ("") and not null.
|
static String |
join(String[] strings,
String separator)
连接字符串数组
|
static String |
joinWithComma(String... strings)
默认逗号分隔的字符串
|
static String |
objectsToString(Object[] args)
对象数组转string
|
static String[] |
split(String src,
String separator)
按分隔符分隔的数组,包含空值
例如 "1,2,,3," 返回 [1,2,,3,] 5个值 |
static String[] |
splitWithCommaOrSemicolon(String src)
按逗号或者分号分隔的数组,排除空字符
例如 " 1,2 ,, 3 , " 返回 [1,2,3] 3个值 " 1;2 ;; 3 ; " 返回 [1,2,3] 3个值 |
static String |
substringAfter(String str,
String separator)
取得第一个出现的分隔子串之后的子串。
|
static String |
toString(byte[] bytes,
String charsetName)
Converts a
byte[] to a String using the specified character encoding. |
static String |
toString(Object o)
对象转string
|
static String |
toString(Object o,
String defaultVal)
对象转string
|
static String |
trim(String str)
StringUtils.trim(null) = null
StringUtils.trim("") = ""
StringUtils.trim(" ") = ""
StringUtils.trim("abc") = "abc"
StringUtils.trim(" abc ") = "abc"
|
static String |
trimToEmpty(String str)
StringUtils.trimToEmpty(null) = ""
StringUtils.trimToEmpty("") = ""
StringUtils.trimToEmpty(" ") = ""
StringUtils.trimToEmpty("abc") = "abc"
StringUtils.trimToEmpty(" abc ") = "abc"
|
static String |
trimToNull(String str)
StringUtils.trimToNull(null) = null
StringUtils.trimToNull("") = null
StringUtils.trimToNull(" ") = null
StringUtils.trimToNull("abc") = "abc"
StringUtils.trimToNull(" abc ") = "abc"
|
public static final String CONTEXT_SEP
"/".public static final String[] EMPTY_STRING_ARRAY
public static boolean isEmpty(CharSequence cs)
Checks if a CharSequence 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 CharSequence. That functionality is available in isBlank().
cs - the CharSequence to check, may be nulltrue if the CharSequence is empty or nullpublic static boolean isNotEmpty(CharSequence cs)
Checks if a CharSequence is not empty ("") and not null.
StringUtils.isNotEmpty(null) = false
StringUtils.isNotEmpty("") = false
StringUtils.isNotEmpty(" ") = true
StringUtils.isNotEmpty("bob") = true
StringUtils.isNotEmpty(" bob ") = true
cs - the CharSequence to check, may be nulltrue if the CharSequence is not empty and not nullpublic static boolean isBlank(CharSequence cs)
Checks if a CharSequence is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
cs - the CharSequence to check, may be nulltrue if the CharSequence is null, empty or whitespacepublic static boolean isNotBlank(CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
StringUtils.isNotBlank(null) = false
StringUtils.isNotBlank("") = false
StringUtils.isNotBlank(" ") = false
StringUtils.isNotBlank("bob") = true
StringUtils.isNotBlank(" bob ") = true
cs - the CharSequence to check, may be nulltrue if the CharSequence is
not empty and not null and not whitespacepublic static String trim(String str)
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 String trimToNull(String str)
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)
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 toString(byte[] bytes, String charsetName) throws UnsupportedEncodingException
byte[] to a String using the specified character encoding.bytes - the byte array to read fromcharsetName - the encoding to use, if null then use the platform defaultUnsupportedEncodingException - If the named charset is not supportedNullPointerException - if the input is nullpublic static String defaultString(Object str)
Returns either the passed in String,
or if the String is null, an empty String ("").
StringUtils.defaultString(null) = ""
StringUtils.defaultString("") = ""
StringUtils.defaultString("bat") = "bat"
str - the String to check, may be nullnullString.valueOf(Object)public static String toString(Object o, String defaultVal)
o - 对象defaultVal - 默认值public static String objectsToString(Object[] args)
args - 对象public static boolean equals(CharSequence s1, CharSequence s2)
s1 - 字符串1s2 - 字符串2public static String[] split(String src, String separator)
src - 原始值separator - 分隔符public static String[] splitWithCommaOrSemicolon(String src)
src - 原始值public static String join(String[] strings, String separator)
strings - 字符串数组separator - 分隔符public static String joinWithComma(String... strings)
strings - 字符串数组public static String substringAfter(String str, String separator)
取得第一个出现的分隔子串之后的子串。
如果字符串为null,则返回null。 如果分隔子串为null或未找到该子串,则返回原字符串。
StringUtil.substringAfter(null, *) = null
StringUtil.substringAfter("", *) = ""
StringUtil.substringAfter(*, null) = ""
StringUtil.substringAfter("abc", "a") = "bc"
StringUtil.substringAfter("abcba", "b") = "cba"
StringUtil.substringAfter("abc", "c") = ""
StringUtil.substringAfter("abc", "d") = ""
StringUtil.substringAfter("abc", "") = "abc"
str - 字符串separator - 要搜索的分隔子串null,则返回nullCopyright © 2008–2018 The Ant Financial. All rights reserved.