public final class Strings
extends java.lang.Object
String
-related utilities.Modifier and Type | Method and Description |
---|---|
static java.lang.String |
capitalize(java.lang.String name)
Returns a new string with the first character in upper case.
|
static java.lang.String |
checkNotBlank(java.lang.String string,
java.lang.String stringName)
Deprecated.
|
static java.lang.String |
emptyToNull(java.lang.String string)
If the string is
empty , returns null ,
otherwise returns the given string. |
static java.util.List<java.lang.String> |
getTokens(java.lang.String css)
Returns a list of trimmed tokens from given token list.
|
static boolean |
isEmpty(java.lang.String string)
Returns
true if the string argument is null or it contains whitespace
characters only, otherwise returns false . |
static boolean |
isNotEmpty(java.lang.String string)
Returns
false if the string argument is null or it contains
whitespace characters only, otherwise returns true . |
static java.lang.String |
join(java.lang.Iterable<?> iterable,
java.lang.String separator)
Joins given list of items with given separator.
|
static java.lang.String |
join(java.lang.Object[] array,
java.lang.String separator)
Joins given list of items with given separator.
|
static java.lang.StringBuilder |
join(java.lang.StringBuilder builder,
java.lang.Iterable<?> iterable,
java.lang.String separator)
Joins given iterable of items with given separator.
|
static java.lang.StringBuilder |
join(java.lang.StringBuilder builder,
java.lang.Object[] array,
java.lang.String separator)
Joins given array of items with given separator.
|
static java.lang.String |
limitLength(java.lang.String str,
int maxLength)
Limits the length of a string to a given length if the length of the string
is greater then the maximal desired length.
|
static java.lang.String |
ltrim(java.lang.String s)
Returns the left-side trim of the given string.
|
static java.lang.String |
nullToEmpty(java.lang.String string)
If the given string is
null , returns an empty string,
otherwise returns the given string. |
static java.lang.String |
rtrim(java.lang.String s)
Returns the right-side trim of the given string.
|
static java.lang.String |
toNullAwareString(java.lang.String string)
Returns given string with enclosing apostrophes (e.g.
'manager' ) if the string argument is not null, otherwise it
returns null (string). |
@Deprecated public static java.lang.String checkNotBlank(java.lang.String string, java.lang.String stringName)
Assert.checkNotBlank(String, String)
null
and does not contain just whitespace characters).string
- the string to check if it is not blankstringName
- the name of the string variable that is checked (used for
displaying in a thrown exception)java.lang.NullPointerException
- (unchecked)
if the string
argument is null
java.lang.IllegalArgumentException
- (unchecked)
if the string
argument contains just whitespace
characterspublic static boolean isEmpty(java.lang.String string)
true
if the string
argument is null
or it contains whitespace
characters only, otherwise returns false
. This method is the complement of the
isNotEmpty(String)
method.string
- any String
instance. Can be null
true
if the string
argument is null
or it contains whitespace
characters only, otherwise false
public static boolean isNotEmpty(java.lang.String string)
false
if the string
argument is null
or it contains
whitespace characters only, otherwise returns true
. This method is the complement of
the isEmpty(String)
method.string
- any String
instance. Can be null
false
if the string
argument is null
or it contains
whitespace characters only, otherwise true
public static java.lang.String nullToEmpty(java.lang.String string)
null
, returns an empty string,
otherwise returns the given string.string
- public static java.lang.String emptyToNull(java.lang.String string)
empty
, returns null
,
otherwise returns the given string.string
- null
public static java.lang.String toNullAwareString(java.lang.String string)
'manager'
) if the string argument is not null, otherwise it
returns null
(string).string
- the string to be checked for null
null
(string) if the string argument is null
public static java.util.List<java.lang.String> getTokens(java.lang.String css)
css
- a comma-separated list of strings, may be nullnull
, may be empty.public static java.lang.String join(java.lang.Object[] array, java.lang.String separator)
join(["foo",
"bar", "baz"], ", ")
(note the space after comma.
null
items are represented as empty strings.
array
- the items, not null. String.valueOf(Object)
is used on the items to convert it to string.separator
- the separator character to usenull
if null array inputpublic static java.lang.StringBuilder join(java.lang.StringBuilder builder, java.lang.Object[] array, java.lang.String separator)
builder
- not nullarray
- not nullseparator
- public static java.lang.String join(java.lang.Iterable<?> iterable, java.lang.String separator)
join(["foo",
"bar", "baz"], ", ")
(note the space after comma.
null
items are represented as empty strings.
iterable
- the items, not null. String.valueOf(Object)
is used on the items to convert it to string.separator
- the separator character to use, not null.null
if null array inputpublic static java.lang.StringBuilder join(java.lang.StringBuilder builder, java.lang.Iterable<?> iterable, java.lang.String separator)
builder
- not nulliterable
- not nullseparator
- public static java.lang.String limitLength(java.lang.String str, int maxLength)
str
- the string the length of which should be limited to the maximal
lengthmaxLength
- the desired maximal length of the stringmaxLength
parameter. If the string
is null
then null
is returned.java.lang.IllegalArgumentException
- if the maxLength
is negativepublic static java.lang.String ltrim(java.lang.String s)
s
- public static java.lang.String rtrim(java.lang.String s)
s
- public static java.lang.String capitalize(java.lang.String name)
name
- Copyright © 2007-2020 Whitestein Technologies. All Rights Reserved.