Class Strings
- java.lang.Object
-
- org.apache.logging.log4j.util.Strings
-
public final class Strings extends java.lang.ObjectConsider this class private.- See Also:
- Apache Commons Lang
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringEMPTYThe empty string.static java.lang.StringLINE_SEPARATOROS-dependent line separator, defaults to"\n"if the system property""line.separator"cannot be read.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringdquote(java.lang.String str)Returns a double quoted string.static booleanisBlank(java.lang.String s)Checks if a String is blank.static booleanisEmpty(java.lang.CharSequence cs)Checks if a CharSequence is empty ("") or null.static booleanisNotBlank(java.lang.String s)Checks if a String is not blank.static booleanisNotEmpty(java.lang.CharSequence cs)Checks if a CharSequence is not empty ("") and not null.static java.lang.Stringjoin(java.lang.Iterable<?> iterable, char separator)Joins the elements of the providedIterableinto a single String containing the provided elements.static java.lang.Stringjoin(java.util.Iterator<?> iterator, char separator)Joins the elements of the providedIteratorinto a single String containing the provided elements.static java.lang.Stringleft(java.lang.String str, int len)Gets the leftmostlencharacters of a String.static java.lang.Stringquote(java.lang.String str)Returns a quoted string.static java.lang.StringtoRootUpperCase(java.lang.String str)Shorthand forstr.toUpperCase(Locale.ROOT);static java.lang.StringtrimToNull(java.lang.String str)Removes control characters (char <= 32) from both ends of this String returningnullif the String is empty ("") after the trim or if it isnull.
-
-
-
Field Detail
-
EMPTY
public static final java.lang.String EMPTY
The empty string.- See Also:
- Constant Field Values
-
LINE_SEPARATOR
public static final java.lang.String LINE_SEPARATOR
OS-dependent line separator, defaults to"\n"if the system property""line.separator"cannot be read.
-
-
Method Detail
-
dquote
public static java.lang.String dquote(java.lang.String str)
Returns a double quoted string.- Parameters:
str- a String- Returns:
"str"
-
isBlank
public static boolean isBlank(java.lang.String s)
Checks if a String is blank. A blank string is one that isnull, empty, or when trimmed usingString.trim()is empty.- Parameters:
s- the String to check, may benull- Returns:
trueif the String isnull, empty, or trims to empty.
-
isEmpty
public static boolean isEmpty(java.lang.CharSequence cs)
Checks if a CharSequence is empty ("") or null.
Strings.isEmpty(null) = true Strings.isEmpty("") = true Strings.isEmpty(" ") = false Strings.isEmpty("bob") = false Strings.isEmpty(" bob ") = falseNOTE: This method changed in Lang version 2.0. It no longer trims the CharSequence. That functionality is available in isBlank().
Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.isEmpty(CharSequence)
- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is empty or null
-
isNotBlank
public static boolean isNotBlank(java.lang.String s)
Checks if a String is not blank. The opposite ofisBlank(String).- Parameters:
s- the String to check, may benull- Returns:
trueif the String is non-nulland has content after being trimmed.
-
isNotEmpty
public static boolean isNotEmpty(java.lang.CharSequence cs)
Checks if a CharSequence is not empty ("") and not null.
Strings.isNotEmpty(null) = false Strings.isNotEmpty("") = false Strings.isNotEmpty(" ") = true Strings.isNotEmpty("bob") = true Strings.isNotEmpty(" bob ") = trueCopied from Apache Commons Lang org.apache.commons.lang3.StringUtils.isNotEmpty(CharSequence)
- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is not empty and not null
-
join
public static java.lang.String join(java.lang.Iterable<?> iterable, char separator)Joins the elements of the provided
Iterableinto a single String containing the provided elements.No delimiter is added before or after the list. Null objects or empty strings within the iteration are represented by empty strings.
- Parameters:
iterable- theIterableproviding the values to join together, may be nullseparator- the separator character to use- Returns:
- the joined String,
nullif null iterator input
-
join
public static java.lang.String join(java.util.Iterator<?> iterator, char separator)Joins the elements of the provided
Iteratorinto a single String containing the provided elements.No delimiter is added before or after the list. Null objects or empty strings within the iteration are represented by empty strings.
- Parameters:
iterator- theIteratorof values to join together, may be nullseparator- the separator character to use- Returns:
- the joined String,
nullif null iterator input
-
left
public static java.lang.String left(java.lang.String str, int len)Gets the leftmost
lencharacters of a String.If
lencharacters are not available, or the String isnull, the String will be returned without an exception. An empty String is returned if len is negative.StringUtils.left(null, *) = null StringUtils.left(*, -ve) = "" StringUtils.left("", *) = "" StringUtils.left("abc", 0) = "" StringUtils.left("abc", 2) = "ab" StringUtils.left("abc", 4) = "abc"Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.
- Parameters:
str- the String to get the leftmost characters from, may be nulllen- the length of the required String- Returns:
- the leftmost characters,
nullif null String input
-
quote
public static java.lang.String quote(java.lang.String str)
Returns a quoted string.- Parameters:
str- a String- Returns:
'str'
-
trimToNull
public static java.lang.String trimToNull(java.lang.String str)
Removes control characters (char <= 32) from both ends of this String returning
nullif the String is empty ("") after the trim or if it isnull.The String is trimmed using
String.trim(). Trim removes start and end characters <= 32.Strings.trimToNull(null) = null Strings.trimToNull("") = null Strings.trimToNull(" ") = null Strings.trimToNull("abc") = "abc" Strings.trimToNull(" abc ") = "abc"Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.trimToNull(String)
- Parameters:
str- the String to be trimmed, may be null- Returns:
- the trimmed String,
nullif only chars <= 32, empty or null String input
-
toRootUpperCase
public static java.lang.String toRootUpperCase(java.lang.String str)
Shorthand forstr.toUpperCase(Locale.ROOT);- Parameters:
str- The string to upper case.- Returns:
- a new string
- See Also:
String.toLowerCase(Locale)
-
-