public abstract class StringUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
BANG |
static java.lang.String |
COMMA |
static java.lang.String |
DASH |
static java.lang.String |
DOT |
static java.lang.String |
ELLIPSIS |
static java.lang.String |
EMPTY |
static java.lang.String |
NEW_LINE |
static java.lang.String |
PIPE |
static java.lang.String |
SLASH |
static java.lang.String |
SPACE |
static java.lang.String |
UNDERSCORE |
| Constructor and Description |
|---|
StringUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
capitalize(java.lang.String text) |
static java.lang.String |
capitalizeWords(java.lang.String str)
Capitalizes all the whitespace separated words in a String.
|
static java.lang.String |
capitalizeWords(java.lang.String str,
char[] delimiters)
Capitalizes all the delimiter separated words in a String.
|
static java.lang.String |
defaultString(java.lang.String str)
Returns either the passed in String, or if the String is
null, an empty String (""). |
static java.lang.String |
defaultString(java.lang.String str,
java.lang.String defaultString) |
static java.lang.Boolean |
equal(java.lang.String text1,
java.lang.String text2) |
static java.util.Set<java.lang.String> |
extractPlaceHolders(java.lang.String string)
Extract all the placeholder's names of the string
|
static java.lang.String |
getFirstToken(java.lang.String string)
Returns the first token of the string if that string can be split by a ",", else return the unmodified input
string
|
static java.lang.String |
getFirstToken(java.lang.String string,
java.lang.String token)
Returns the first token of the string if that string can be split by the token, else return the unmodified input
string
|
static java.lang.String |
getNotEmptyString(java.lang.String text) |
static boolean |
hasOnlyCharacters(java.lang.String name) |
static boolean |
isBlank(java.lang.String str)
Checks if a String is whitespace, empty ("") or null.
|
static java.lang.Boolean |
isEmpty(java.lang.String text) |
static boolean |
isNotBlank(java.lang.String str)
Checks if a String is not empty (""), not null and not whitespace only.
|
static java.lang.Boolean |
isNotEmpty(java.lang.String text) |
static java.lang.String |
join(java.util.Collection<?> objectsToJoin)
Joins all the strings in the list in a single one separated by ','.
|
static java.lang.String |
join(java.util.Collection<?> objectsToJoin,
java.lang.String separator)
Joins all the strings in the list in a single one separated by the separator sequence.
|
static java.lang.CharSequence |
removeTrailingWhitespaces(java.lang.CharSequence charSequence) |
static java.lang.String |
replaceValues(java.lang.String template,
java.util.Map<java.lang.String,java.lang.String> values) |
static java.util.Collection<java.lang.String> |
splitToCollectionWithCommaSeparator(java.lang.String text) |
static java.util.Collection<java.lang.String> |
splitToCollectionWithCommaSeparator(java.lang.String text,
java.lang.String separator) |
static java.lang.String |
toAlphanumeric(java.lang.String value)
Transform the received value removing all the not alphanumeric or spaces characters
|
static java.lang.String |
truncate(java.lang.String text,
java.lang.Integer maxCharacters)
Truncate the text adding "...".
|
static java.lang.String |
truncate(java.lang.String text,
java.lang.Integer maxCharacters,
java.lang.Boolean truncateWords)
Truncate the text adding "..." if the truncateWords parameter is true.
|
static java.lang.String |
wordWrapToTwoLines(java.lang.String text,
int minLength)
This method word wrap a text to two lines if the text has multiple words and its length is greater than the
specified minLength.
|
public static final java.lang.String EMPTY
public static final java.lang.String ELLIPSIS
public static final java.lang.String COMMA
public static final java.lang.String SPACE
public static final java.lang.String DASH
public static final java.lang.String SLASH
public static final java.lang.String DOT
public static final java.lang.String NEW_LINE
public static final java.lang.String UNDERSCORE
public static final java.lang.String BANG
public static final java.lang.String PIPE
public static java.lang.String getNotEmptyString(java.lang.String text)
public static java.lang.Boolean equal(java.lang.String text1,
java.lang.String text2)
public static java.lang.Boolean isEmpty(java.lang.String text)
public static java.lang.Boolean isNotEmpty(java.lang.String text)
public static boolean isBlank(java.lang.String str)
Checks if a String is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
str - the String to check, may be nulltrue if the String is null, empty or whitespacepublic static boolean isNotBlank(java.lang.String str)
Checks if a String is not empty (""), not null and not whitespace only.
StringUtils.isNotBlank(null) = false
StringUtils.isNotBlank("") = false
StringUtils.isNotBlank(" ") = false
StringUtils.isNotBlank("bob") = true
StringUtils.isNotBlank(" bob ") = true
str - the String to check, may be nulltrue if the String is not empty and not null and not whitespacepublic static java.lang.String defaultString(java.lang.String str)
Returns either the passed in String, or if the String is null, an empty String ("").
StringUtils.defaultString(null) = ""
StringUtils.defaultString("") = ""
StringUtils.defaultString("bat") = "bat"
str - the String to check, may be nullnullpublic static java.lang.String defaultString(java.lang.String str,
java.lang.String defaultString)
public static java.lang.String capitalize(java.lang.String text)
public static java.lang.String capitalizeWords(java.lang.String str)
Capitalizes all the whitespace separated words in a String. Only the first letter of each word is changed. To
convert the rest of each word to lowercase at the same time, use capitalize(String).
Whitespace is defined by Character.isWhitespace(char). A null input String returns
null. Capitalization uses the unicode title case, normally equivalent to upper case.
WordUtils.capitalize(null) = null
WordUtils.capitalize("") = ""
WordUtils.capitalize("i am FINE") = "I Am FINE"
str - the String to capitalize, may be nullnull if null String inputpublic static java.lang.String capitalizeWords(java.lang.String str,
char[] delimiters)
Capitalizes all the delimiter separated words in a String. Only the first letter of each word is changed.
The delimiters represent a set of characters understood to separate words. The first string character and the first non-delimiter character after a delimiter will be capitalized.
A null input String returns null. Capitalization uses the unicode title case, normally
equivalent to upper case.
WordUtils.capitalize(null, *) = null
WordUtils.capitalize("", *) = ""
WordUtils.capitalize(*, new char[0]) = *
WordUtils.capitalize("i am fine", null) = "I Am Fine"
WordUtils.capitalize("i aM.fine", {'.'}) = "I aM.Fine"
str - the String to capitalize, may be nulldelimiters - set of characters to determine capitalization, null means whitespacenull if null String inputpublic static java.lang.String join(java.util.Collection<?> objectsToJoin,
java.lang.String separator)
objectsToJoin - The objects to join.separator - The separator sequence.public static java.lang.String join(java.util.Collection<?> objectsToJoin)
objectsToJoin - The objects to join.public static java.lang.String truncate(java.lang.String text,
java.lang.Integer maxCharacters,
java.lang.Boolean truncateWords)
text - The text to truncatemaxCharacters - The maximum amount of characters allowed for the returned texttruncateWords - True if the words should be truncatedpublic static java.lang.String truncate(java.lang.String text,
java.lang.Integer maxCharacters)
text - The text to truncatemaxCharacters - The maximum amount of characters allowed for the returned textpublic static java.util.Set<java.lang.String> extractPlaceHolders(java.lang.String string)
string - The whole string with placeholderspublic static java.lang.String toAlphanumeric(java.lang.String value)
value - The string to transformpublic static java.util.Collection<java.lang.String> splitToCollectionWithCommaSeparator(java.lang.String text)
public static java.util.Collection<java.lang.String> splitToCollectionWithCommaSeparator(java.lang.String text,
java.lang.String separator)
public static java.lang.String getFirstToken(java.lang.String string,
java.lang.String token)
string - The string to splittoken - The token to use as splitterpublic static java.lang.String getFirstToken(java.lang.String string)
string - The string to splitpublic static java.lang.String wordWrapToTwoLines(java.lang.String text,
int minLength)
text - A Sting, the text to word wrap to two lines.minLength - The min text length to apply word wrap.public static java.lang.String replaceValues(java.lang.String template,
java.util.Map<java.lang.String,java.lang.String> values)
public static boolean hasOnlyCharacters(java.lang.String name)
public static java.lang.CharSequence removeTrailingWhitespaces(java.lang.CharSequence charSequence)
charSequence - a CharSequence, the charSequence to trim.