public class StringUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isBlank(CharSequence charSequence)
Checks if a
CharSequence is empty (""), null or whitespace only. |
static boolean |
isEmpty(CharSequence charSequence)
Checks if a
CharSequence is empty ("") or null. |
static String |
requireNonBlankAndTrim(String string,
String message)
Checks that the specified string is not
null, empty (""), or blank
(containing whitespace only). |
public static String requireNonBlankAndTrim(String string, String message)
null, empty (""), or blank
(containing whitespace only). If the string is valid, returns a copy of it, trimmed;
otherwise, throws an IllegalArgumentException.
This method is designed primarily for doing parameter validation in methods and constructors with multiple parameters, as demonstrated below:
public Foo(Bar bar)
{
this.bar = StringUtils.requireNonBlankAndTrim(bar, "bar must not be blank");
}
string - the string to checkmessage - detail message for the exception to be used if the string a blankstring, trimmed, if not null or blankIllegalArgumentException - if string is null or blankpublic static boolean isEmpty(CharSequence charSequence)
CharSequence is empty ("") or null.charSequence - the CharSequence to check, may be nulltrue if the CharSequence is empty or nullpublic static boolean isBlank(CharSequence charSequence)
CharSequence is empty (""), null or whitespace only.charSequence - the CharSequence to check, may be nulltrue if the CharSequence is null, empty or whitespace onlyCopyright © 2025. All rights reserved.