public final class Strings extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
emptyToNull(String string)
Returns the given string if it is nonempty;
null otherwise. |
static boolean |
isNullOrEmpty(String string)
Returns
true if the given string is null or is the empty string. |
static String |
nullToEmpty(String string)
Returns the given string if it is non-null; the empty string otherwise.
|
static String |
repeat(String string,
int count)
Returns a string consisting of a specific number of concatenated copies of an input string.
|
public static String nullToEmpty(@Nullable String string)
string - the string to test and possibly returnstring itself if it is non-null; "" if it is null@Nullable public static String emptyToNull(@Nullable 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 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 stringpublic static String repeat(String string, int count)
repeat("hey", 3) returns the string "heyheyhey".string - any non-null stringcount - the number of times to repeat it; a nonnegative integerstring repeated count times (the empty string if
count is zero)IllegalArgumentException - if count is negativeCopyright © 2021. All rights reserved.