public class StringUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
EMPTY |
static int |
INDEX_NOT_FOUND |
| 构造器和说明 |
|---|
StringUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
composeMessage(String source,
String... replacement) |
static boolean |
contains(String str,
String searchStr) |
static int |
countOccurrencesOf(String str,
String sub)
Count the occurrences of the substring in string s.
|
static String |
defaultIfEmpty(String str,
String defaultStr) |
static boolean |
equals(String str1,
String str2) |
static String |
escapeSql(String str) |
static boolean |
hasLength(CharSequence str)
检查包含空白字符在内的字符系列长度
StringUtils.hasLength(null) = false
StringUtils.hasLength("") = false
StringUtils.hasLength(" ") = true
StringUtils.hasLength("Hello") = true
|
static boolean |
hasText(CharSequence str) |
static boolean |
hasText(String str)
Check whether the given String has actual text.
|
static boolean |
isEmpty(String str) |
static String |
join(Object[] obj,
String split)
{null,"",null,2,3} --> 2,3
{"",2,"",2,"",} --> 2,2
|
static String |
substringBefore(String str,
String separator) |
static String |
substringBetween(String str,
String tag) |
static String |
substringBetween(String str,
String open,
String close) |
static String[] |
tokenizeToStringArray(String str,
String delimiters)
Tokenize the given String into a String array via a StringTokenizer.
|
static String[] |
tokenizeToStringArray(String str,
String delimiters,
boolean trimTokens,
boolean ignoreEmptyTokens)
Tokenize the given String into a String array via a StringTokenizer.
|
static String[] |
toStringArray(Collection<String> collection)
Copy the given Collection into a String array.
|
public static final int INDEX_NOT_FOUND
public static boolean isEmpty(String str)
public static String join(Object[] obj, String split)
obj - split - public static String[] tokenizeToStringArray(String str, String delimiters)
The given delimiters string is supposed to consist of any number of
delimiter characters. Each of those characters can be used to separate
tokens. A delimiter is always a single character; for multi-character
delimiters, consider using delimitedListToStringArray
str - the String to tokenizedelimiters - the delimiter characters, assembled as String
(each of those characters is individually considered as delimiter).StringTokenizer,
String.trim()public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
The given delimiters string is supposed to consist of any number of
delimiter characters. Each of those characters can be used to separate
tokens. A delimiter is always a single character; for multi-character
delimiters, consider using delimitedListToStringArray
str - the String to tokenizedelimiters - the delimiter characters, assembled as String
(each of those characters is individually considered as delimiter)trimTokens - trim the tokens via String's trimignoreEmptyTokens - omit empty tokens from the result array
(only applies to tokens that are empty after trimming; StringTokenizer
will not consider subsequent delimiters as token in the first place).null if the input String
was null)StringTokenizer,
String.trim()public static String[] toStringArray(Collection<String> collection)
collection - the Collection to copynull if the passed-in
Collection was null)public static boolean hasText(String str)
true if the string not null,
its length is greater than 0, and it contains at least one non-whitespace character.str - the String to check (may be null)true if the String is not null, its length is
greater than 0, and it does not contain whitespace onlyhasText(CharSequence)public static boolean hasText(CharSequence str)
public static boolean hasLength(CharSequence str)
StringUtils.hasLength(null) = false
StringUtils.hasLength("") = false
StringUtils.hasLength(" ") = true
StringUtils.hasLength("Hello") = true
str - the CharSequence to check (may be null)true if the CharSequence is not null and has lengthhasText(String)public static int countOccurrencesOf(String str, String sub)
str - string to search in. Return 0 if this is null.sub - string to search for. Return 0 if this is null.Copyright © 2018. All rights reserved.