public final class StringUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
EMPTY_STRING
Constant for an empty String.
|
static String[] |
EMPTY_STRING_ARRAY
Constant for an empty String array.
|
static String |
FALSE
Constant for the value false.
|
static char |
SPACE
a space.
|
static String |
TRUE
Constant for the value true.
|
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
capitalize(String str)
Capitalizes the first character of the provided string.
|
static String |
convertDotToUnderscore(String dottedProperty)
Replace the dots in the property with underscore and
transform to uppercase.
|
static String |
convertDotToUnderscore(String dottedProperty,
boolean uppercase)
Replace the dots in the property with underscore and
transform to uppercase based on given flag.
|
static boolean |
hasText(CharSequence str)
Return whether the given string has non whitespace characters.
|
static List<String> |
internListOf(Object... objects)
Converts the given objects into a set of interned strings contained within an internal pool of sets.
|
static Map<String,Object> |
internMapOf(Object... values)
Converts the given objects into a map of interned strings.
|
static boolean |
isDigits(String str)
Is the given string a series of digits.
|
static boolean |
isEmpty(CharSequence str)
Return whether the given string is empty.
|
static boolean |
isNotEmpty(CharSequence str)
Return whether the given string is not empty.
|
static boolean |
isTrue(String booleanString)
Is the boolean string true.
|
static Locale |
parseLocale(String localeValue)
Parse the given
String value into a Locale , accepting
the Locale.toString() format as well as BCP 47 language tags. |
static String |
prependUri(String baseUri,
String uri)
Prepends a partial uri and normalizes / characters.
|
static Iterable<String> |
splitOmitEmptyStrings(CharSequence sequence,
char splitCharacter)
Fast split by one character iterable.
|
static Iterator<String> |
splitOmitEmptyStringsIterator(CharSequence sequence,
char splitCharacter)
Fast split by one character iterator.
|
static List<String> |
splitOmitEmptyStringsList(CharSequence sequence,
char splitCharacter)
Fast split by one character iterable.
|
static String[] |
tokenizeToStringArray(String str,
String delimiters)
Tokenize the given String into a String array via a StringTokenizer.
|
static String[] |
tokenizeToStringArray(String str,
String delimiters,
boolean trimTokens,
boolean ignoreEmptyTokens)
Tokenize the given String into a String array via a StringTokenizer.
|
static String |
trimLeading(String str,
Predicate<Character> predicate)
Returns a new string without any leading characters that match the supplied predicate.
|
static String |
trimLeadingCharacter(String str,
char c)
Returns a new string without any leading characters that match the supplied character.
|
static String |
trimLeadingWhitespace(String str)
Returns a new string without any leading whitespace.
|
static String |
trimToNull(String string)
Trims the supplied string.
|
public static final String TRUE
public static final String FALSE
public static final String[] EMPTY_STRING_ARRAY
public static final String EMPTY_STRING
public static final char SPACE
public static boolean isEmpty(@Nullable CharSequence str)
str
- The stringpublic static boolean isNotEmpty(@Nullable CharSequence str)
str
- The stringpublic static boolean hasText(@Nullable CharSequence str)
str
- The stringpublic static List<String> internListOf(Object... objects)
String.intern()
.objects
- The objectspublic static Map<String,Object> internMapOf(Object... values)
String.intern()
.values
- The objectsCollectionUtils.mapOf(Object...)
public static boolean isDigits(String str)
str
- The string@Nullable public static Locale parseLocale(String localeValue)
String
value into a Locale
, accepting
the Locale.toString()
format as well as BCP 47 language tags.localeValue
- the locale value: following either Locale's
toString()
format ("en", "en_UK", etc), also accepting spaces as
separators (as an alternative to underscores), or BCP 47 (e.g. "en-UK")
as specified by Locale.forLanguageTag(java.lang.String)
on Java 7+
Copied from the Spring Framework while retaining all license, copyright and author information.
Locale
instance, or null
if noneIllegalArgumentException
- in case of an invalid locale specificationLocale.forLanguageTag(java.lang.String)
public static String trimLeadingWhitespace(String str)
str
- The stringpublic static String trimLeadingCharacter(String str, char c)
str
- The stringc
- The character to removepublic static String trimLeading(String str, Predicate<Character> predicate)
str
- The stringpredicate
- The predicate to test characters againstpublic static String[] tokenizeToStringArray(String str, String delimiters)
The given delimiters string is supposed to consist of any number of
delimiter characters. Each of those characters can be used to separate
tokens. A delimiter is always a single character; for multi-character
delimiters, consider using delimitedListToStringArray
Copied from the Spring Framework while retaining all license, copyright and author information.
str
- the String to tokenizedelimiters
- the delimiter characters, assembled as String
(each of those characters is individually considered as delimiter).StringTokenizer
,
String.trim()
public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
The given delimiters string is supposed to consist of any number of
delimiter characters. Each of those characters can be used to separate
tokens. A delimiter is always a single character; for multi-character
delimiters, consider using delimitedListToStringArray
Copied from the Spring Framework while retaining all license, copyright and author information.
str
- the String to tokenizedelimiters
- the delimiter characters, assembled as String
(each of those characters is individually considered as delimiter)trimTokens
- trim the tokens via String's trim
ignoreEmptyTokens
- omit empty tokens from the result array
(only applies to tokens that are empty after trimming; StringTokenizer
will not consider subsequent delimiters as token in the first place).null
if the input String
was null
)StringTokenizer
,
String.trim()
public static String convertDotToUnderscore(String dottedProperty)
dottedProperty
- The property with dots, example - a.b.cpublic static String convertDotToUnderscore(String dottedProperty, boolean uppercase)
dottedProperty
- The property with dots, example - a.b.cuppercase
- To transform to uppercase stringpublic static String prependUri(String baseUri, String uri)
baseUri
- The uri to prepend. Eg. /foouri
- The uri to combine with the baseUri. Eg. /barpublic static String capitalize(String str)
str
- The string to capitalize@Nullable public static String trimToNull(@Nullable String string)
string
- the string to trimpublic static boolean isTrue(String booleanString)
booleanString
- The boolean stringpublic static Iterable<String> splitOmitEmptyStrings(CharSequence sequence, char splitCharacter)
String.split(String)
where it's used with one character.sequence
- The sequence to splitsplitCharacter
- The split characterpublic static List<String> splitOmitEmptyStringsList(CharSequence sequence, char splitCharacter)
String.split(String)
where it's used with one character.sequence
- The sequence to splitsplitCharacter
- The split characterpublic static Iterator<String> splitOmitEmptyStringsIterator(CharSequence sequence, char splitCharacter)
String.split(String)
where it's used with one character.sequence
- The sequence to splitsplitCharacter
- The split character