public final class Strings extends Object
String or CharSequence
instances.| Modifier and Type | Method and Description |
|---|---|
static String |
emptyToNull(String string)
Returns the given string if it is nonempty;
null otherwise. |
static boolean |
isBlank(String str)
Checks if a string is whitespace, empty ("") or null.
|
static boolean |
isNotBlank(String str)
Checks if a string is not empty (""), not null and not whitespace only.
|
static boolean |
isNullOrEmpty(String str)
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[] |
split(String str,
char separator)
Splits the provided text into an array, separator specified.
|
static String[] |
split(String str,
char separator,
boolean preserveAllTokens)
Splits the provided text into an array, separator specified,
if true, preserving all tokens, including empty tokens created
by adjacent separators.
|
static String |
toString(Object obj) |
public static String nullToEmpty(String string)
public static String emptyToNull(String string)
null otherwise.public static boolean isNullOrEmpty(String str)
true if the given string is null or is the empty string.public static boolean isBlank(String str)
Strings.isBlank(null) = true Strings.isBlank("") = true Strings.isBlank(" ") = true Strings.isBlank("bob") = false Strings.isBlank(" bob ") = false
public static boolean isNotBlank(String str)
Strings.isNotBlank(null) = false Strings.isNotBlank("") = false Strings.isNotBlank(" ") = false Strings.isNotBlank("bob") = true Strings.isNotBlank(" bob ") = true
public static String[] split(String str, char separator)
A null input String returns null.
Strings.split(null, *) = null Strings.split("", *) = [] Strings.split("a.b.c", '.') = ["a", "b", "c"] Strings.split("a..b.c", '.') = ["a", "b", "c"] Strings.split("a:b:c", '.') = ["a:b:c"] Strings.split("a b c", ' ') = ["a", "b", "c"]
public static String[] split(String str, char separator, boolean preserveAllTokens)
A null input String returns null.
Strings.split(null, *, true) = null Strings.split("", *, true) = [] Strings.split("a.b.c", '.', true) = ["a", "b", "c"] Strings.split("a..b.c", '.', true) = ["a", "", "b", "c"] Strings.split("a:b:c", '.', true) = ["a:b:c"] Strings.split("a b c", ' ', true) = ["a", "b", "c"] Strings.split("a b c ", ' ', true) = ["a", "b", "c", ""] Strings.split("a b c ", ' ', true) = ["a", "b", "c", "", ""] Strings.split(" a b c", ' ', true) = ["", a", "b", "c"] Strings.split(" a b c", ' ', true) = ["", "", a", "b", "c"] Strings.split(" a b c ", ' ', true) = ["", a", "b", "c", ""]
Copyright © 2023. All rights reserved.