public class Strings
extends java.lang.Object
| Constructor and Description |
|---|
Strings() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
emptyToNull(java.lang.String string)
Returns the given string if it is nonempty;
null otherwise. |
static boolean |
isNullOrEmpty(java.lang.String string)
Returns
true if the given string is null or is the empty string. |
static java.lang.String |
nullToEmpty(java.lang.String string)
Returns the given string if it is non-null; the empty string otherwise.
|
public static java.lang.String nullToEmpty(@Nullable
java.lang.String string)
string - the string to test and possibly returnstring itself if it is non-null; "" if it is null@Nullable
public static java.lang.String emptyToNull(@Nullable
java.lang.String string)
null otherwise.string - the string to test and possibly returnstring itself if it is nonempty; null if it is
empty or nullpublic static boolean isNullOrEmpty(@Nullable
java.lang.String string)
true if the given string is null or is the empty string.
Consider normalizing your string references with nullToEmpty(java.lang.String).
If you do, you can use String.isEmpty() instead of this
method, and you won't need special null-safe forms of methods like String.toUpperCase(java.util.Locale) either. Or, if you'd like to normalize "in the other
direction," converting empty strings to null, you can use emptyToNull(java.lang.String).
string - a string reference to checktrue if the string is null or is the empty string