public class StringUtils extends Object
Operations on String
that are
null
safe.
The StringUtils
class defines certain words related to
String handling.
null
""
)' '
, char 32)Character.isWhitespace(char)
String.trim()
StringUtils
handles null
input Strings quietly.
That is to say that a null
input will return null
.
Where a boolean
or int
is being returned
details vary by method.
A side effect of the null
handling is that a
NullPointerException
should be considered a bug in
StringUtils
.
Methods in this class give sample code to explain their operation.
The symbol *
is used to indicate any input including null
.
#ThreadSafe#
String
Modifier and Type | Field and Description |
---|---|
static String |
EMPTY
The empty String
"" . |
Modifier and Type | Method and Description |
---|---|
static boolean |
containsAny(CharSequence cs,
char... searchChars)
Checks if the CharSequence contains any character in the given.
|
static boolean |
isEmpty(CharSequence cs)
Checks if a CharSequence is empty ("") or null.
|
public static final String EMPTY
""
.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 containsAny(CharSequence cs, char... searchChars)
Checks if the CharSequence contains any character in the given. set of characters.
A null
CharSequence will return false
.
A null
or zero length search array will return false
.
StringUtils.containsAny(null, *) = false StringUtils.containsAny("", *) = false StringUtils.containsAny(*, null) = false StringUtils.containsAny(*, []) = false StringUtils.containsAny("zzabyycdxx",['z','a']) = true StringUtils.containsAny("zzabyycdxx",['b','y']) = true StringUtils.containsAny("aba", ['z']) = false
cs
- the CharSequence to check, may be nullsearchChars
- the chars to search for, may be nulltrue
if any of the chars are found,
false
if no match or null inputCopyright © 2019. All rights reserved.