Top Description Fields Constructors Methods
org.apache.logging.log4j.util

public final Class Strings

extends Object
Class Inheritance
Annotations
@InternalApi
Imports
java.util.Iterator, .Locale, .Objects

Consider this class private.
See Also
Apache Commons Lang

Field Summary

Modifier and TypeField and Description
private static final String
public static final String
EMPTY

The empty string.

public static final String[]
EMPTY_ARRAY

The empty array.

public static final String
LINE_SEPARATOR

OS-dependent line separator, defaults to "\n" if the system property ""line.separator" cannot be read.

private static final ThreadLocal<StringBuilder>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the concatenated String.
concat
(final String
the first string.
str1
,
final String
the second string.
str2
)

Concatenates 2 Strings without allocation.

public static String

Returns:

"str"
dquote
(final String
a String
str
)

Returns a double quoted string.

public static boolean

Returns:

true if the String is null, empty, or all characters are Character#isWhitespace(char)
isBlank
(final String
the String to check, may be null
s
)

Checks if a String is blank.

public static boolean

Returns:

true if the CharSequence is empty or null
isEmpty
(final CharSequence
the CharSequence to check, may be null
cs
)

Checks if a CharSequence is empty ("") or null.

public static boolean

Returns:

true if the String is non-null and has content after being trimmed.
isNotBlank
(final String
the String to check, may be null
s
)

Checks if a String is not blank.

public static boolean

Returns:

true if the CharSequence is not empty and not null
isNotEmpty
(final CharSequence
the CharSequence to check, may be null
cs
)

Checks if a CharSequence is not empty ("") and not null.

public static String

Returns:

the joined String, null if null iterator input
join
(final Iterable<?>
the Iterable providing the values to join together, may be null
iterable
,
final char
the separator character to use
separator
)

Joins the elements of the provided Iterable into a single String containing the provided elements.

public static String

Returns:

the joined String, null if null iterator input
join
(final Iterator<?>
the Iterator of values to join together, may be null
iterator
,
final char
the separator character to use
separator
)

Joins the elements of the provided Iterator into a single String containing the provided elements.

public static String

Returns:

the leftmost characters, null if null String input
left
(final String
the String to get the leftmost characters from, may be null
str
,
final int
the length of the required String
len
)

Gets the leftmost len characters of a String.

public static String

Returns:

'str'
quote
(final String
a String
str
)

Returns a quoted string.

public static String

Returns:

the new string
repeat
(final String
input string
str
,
final int
the repetition count
count
)

Creates a new string repeating given str count times.

public static String[]
splitList(final String string)

public static String

Returns:

a new string
toRootLowerCase
(final String
The string to upper case.
str
)

Shorthand for str.toLowerCase(Locale.ROOT);

public static String

Returns:

a new string
toRootUpperCase
(final String
The string to lower case.
str
)

Shorthand for str.toUpperCase(Locale.ROOT);

public static String

Returns:

the trimmed String, null if only chars <= 32, empty or null String input
trimToNull
(final String
the String to be trimmed, may be null
str
)

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

COMMA_DELIMITED_REback to summary
private static final String COMMA_DELIMITED_RE
EMPTYback to summary
public static final String EMPTY

The empty string.

EMPTY_ARRAYback to summary
public static final String[] EMPTY_ARRAY

The empty array.

LINE_SEPARATORback to summary
public static final String LINE_SEPARATOR

OS-dependent line separator, defaults to "\n" if the system property ""line.separator" cannot be read.

tempStrback to summary
private static final ThreadLocal<StringBuilder> tempStr

Constructor Detail

Stringsback to summary
private Strings()

Method Detail

concatback to summary
public static String concat(final String str1, final String str2)

Concatenates 2 Strings without allocation.

Parameters
str1:String

the first string.

str2:String

the second string.

Returns:String

the concatenated String.

dquoteback to summary
public static String dquote(final String str)

Returns a double quoted string.

Parameters
str:String

a String

Returns:String

"str"

isBlankback to summary
public static boolean isBlank(final String s)

Checks if a String is blank. A blank string is one that is either null, empty, or all characters are Character#isWhitespace(char).

Parameters
s:String

the String to check, may be null

Returns:boolean

true if the String is null, empty, or all characters are Character#isWhitespace(char)

isEmptyback to summary
public static boolean isEmpty(final 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  ") = false

Note

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:CharSequence

the CharSequence to check, may be null

Returns:boolean

true if the CharSequence is empty or null

isNotBlankback to summary
public static boolean isNotBlank(final String s)

Checks if a String is not blank. The opposite of isBlank(String).

Parameters
s:String

the String to check, may be null

Returns:boolean

true if the String is non-null and has content after being trimmed.

isNotEmptyback to summary
public static boolean isNotEmpty(final 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  ") = true

Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.isNotEmpty(CharSequence)

Parameters
cs:CharSequence

the CharSequence to check, may be null

Returns:boolean

true if the CharSequence is not empty and not null

joinback to summary
public static String join(final Iterable<?> iterable, final char separator)

Joins the elements of the provided Iterable into 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:Iterable<?>

the Iterable providing the values to join together, may be null

separator:char

the separator character to use

Returns:String

the joined String, null if null iterator input

joinback to summary
public static String join(final Iterator<?> iterator, final char separator)

Joins the elements of the provided Iterator into 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:Iterator<?>

the Iterator of values to join together, may be null

separator:char

the separator character to use

Returns:String

the joined String, null if null iterator input

leftback to summary
public static String left(final String str, final int len)

Gets the leftmost len characters of a String.

If len characters are not available, or the String is null, 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:String

the String to get the leftmost characters from, may be null

len:int

the length of the required String

Returns:String

the leftmost characters, null if null String input

quoteback to summary
public static String quote(final String str)

Returns a quoted string.

Parameters
str:String

a String

Returns:String

'str'

repeatback to summary
public static String repeat(final String str, final int count)

Creates a new string repeating given str count times.

Parameters
str:String

input string

count:int

the repetition count

Returns:String

the new string

Exceptions
IllegalArgumentException:
if either str is null or count is negative
splitListback to summary
public static String[] splitList(final String string)
toRootLowerCaseback to summary
public static String toRootLowerCase(final String str)

Shorthand for str.toLowerCase(Locale.ROOT);

Parameters
str:String

The string to upper case.

Returns:String

a new string

See Also
String#toLowerCase(Locale)
toRootUpperCaseback to summary
public static String toRootUpperCase(final String str)

Shorthand for str.toUpperCase(Locale.ROOT);

Parameters
str:String

The string to lower case.

Returns:String

a new string

See Also
String#toLowerCase(Locale)
trimToNullback to summary
public static String trimToNull(final String str)

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null.

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:String

the String to be trimmed, may be null

Returns:String

the trimmed String, null if only chars <= 32, empty or null String input