public class StringUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
EMPTY
The empty String
"". |
static String |
SPACE
A String for a space character.
|
| 限定符 | 构造器和说明 |
|---|---|
private |
StringUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
equals(CharSequence cs1,
CharSequence cs2)
Compares two CharSequences, returning
true if they represent
equal sequences of characters. |
static boolean |
isBlank(CharSequence cs)
Checks if a CharSequence is empty (""), null or whitespace only.
|
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 |
isNumeric(CharSequence cs)
Checks if the CharSequence contains only Unicode digits.
|
static boolean |
regionMatches(CharSequence cs,
boolean ignoreCase,
int thisStart,
CharSequence substring,
int start,
int length)
Green implementation of regionMatches.
|
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 isBlank(CharSequence cs)
Checks if a CharSequence is empty (""), null or whitespace only.
Whitespace is defined by Character.isWhitespace(char).
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 whitespace onlypublic static boolean isNotBlank(CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
Whitespace is defined by Character.isWhitespace(char).
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 whitespace onlypublic static boolean equals(CharSequence cs1, CharSequence cs2)
Compares two CharSequences, returning true if they represent
equal sequences of characters.
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
cs1 - the first CharSequence, may be nullcs2 - the second CharSequence, may be nulltrue if the CharSequences are equal (case-sensitive), or both nullObject.equals(Object)public static boolean regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length)
cs - the CharSequence to be processedignoreCase - whether or not to be case insensitivethisStart - the index to start on the cs CharSequencesubstring - the CharSequence to be looked forstart - the index to start on the substring CharSequencelength - character length of the regionpublic static boolean isNumeric(CharSequence cs)
Checks if the CharSequence contains only Unicode digits. A decimal point is not a Unicode digit and returns false.
null will return false.
An empty CharSequence (length()=0) will return false.
Note that the method does not allow for a leading sign, either positive or negative. Also, if a String passes the numeric test, it may still generate a NumberFormatException when parsed by Integer.parseInt or Long.parseLong, e.g. if the value is outside the range for int or long respectively.
StringUtils.isNumeric(null) = false
StringUtils.isNumeric("") = false
StringUtils.isNumeric(" ") = false
StringUtils.isNumeric("123") = true
StringUtils.isNumeric("१२३") = true
StringUtils.isNumeric("12 3") = false
StringUtils.isNumeric("ab2c") = false
StringUtils.isNumeric("12-3") = false
StringUtils.isNumeric("12.3") = false
StringUtils.isNumeric("-123") = false
StringUtils.isNumeric("+123") = false
cs - the CharSequence to check, may be nulltrue if only contains digits, and is non-nullCopyright © 2023. All rights reserved.