public final class StringUtil extends Object
Modifier and Type | Method and Description |
---|---|
static String |
capitalize(String str)
Capitalizes a String changing the first letter to title case as
per
Character.toTitleCase(char) . |
static boolean |
contains(String val,
char charToSearchFor) |
static boolean |
endsWithIgnoreCase(String str,
String suffix) |
static boolean |
equalsIgnoreCase(String str1,
String str2) |
static boolean |
isBlank(CharSequence cs)
Checks if a CharSequence is whitespace, empty ("") or null.
|
static boolean |
isEmpty(String val) |
static boolean |
isNotBlank(CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
|
static boolean |
isNotEmpty(String val) |
static String |
join(Object[] values,
String joinToken) |
static <T> T |
parse(String val,
Class<T> type)
Parse the given
|
static String |
replace(String str,
String from,
String to)
Replace all instances of
from in str
with to . |
static String[] |
split(String str,
String token,
int max)
Splits the given string on the given token.
|
static String |
stripEnd(String str,
String stripChars)
Strips any of a set of characters from the end of a String.
|
static String |
trim(String str)
Null-safe
String.trim() |
static String |
trimToNull(String str) |
static String |
uncapitalize(String str)
Uncapitalizes a String changing the first letter to title case as
per
Character.toLowerCase(char) . |
public static boolean isEmpty(String val)
true
if the given string is null or empty.public static boolean isNotEmpty(String val)
public static boolean isBlank(CharSequence cs)
Checks if a CharSequence is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = falsePorted over from Apache commons-lang3
cs
- the CharSequence to check, may be nulltrue
if the CharSequence is null, empty or whitespacepublic static boolean isNotBlank(CharSequence cs)
Checks if a CharSequence 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 ") = truePorted over from Apache commons-lang3
cs
- the CharSequence to check, may be nulltrue
if the CharSequence is not empty and not null and not whitespacepublic static boolean contains(String val, char charToSearchFor)
val
- the string to search incharToSearchFor
- the character to search fortrue
if the charToSearchFor is contained in the String valpublic static String[] split(String str, String token, int max)
String.split(String, int)
method, but does
not treat the given token as a regular expression.public static String replace(String str, String from, String to)
from
in str
with to
.str
- the candidate string to replacefrom
- the token to replaceto
- the new tokenpublic static String trim(String str)
String.trim()
public static String trimToNull(String str)
null
if the trimmed string would be empty.public static <T> T parse(String val, Class<T> type)
val
- value to parsetype
- the target type of the the parsed valuepublic static String capitalize(String str)
Capitalizes a String changing the first letter to title case as
per Character.toTitleCase(char)
. No other letters are changed.
StringUtil.capitalize(null) = null StringUtil.capitalize("") = "" StringUtil.capitalize("cat") = "Cat" StringUtil.capitalize("cAt") = "CAt"Ported over from Apache commons-lang3
str
- the String to capitalize, may be nullnull
if null String inputuncapitalize(String)
public static String uncapitalize(String str)
Uncapitalizes a String changing the first letter to title case as
per Character.toLowerCase(char)
. No other letters are changed.
StringUtil.uncapitalize(null) = null StringUtil.uncapitalize("") = "" StringUtil.uncapitalize("Cat") = "cat" StringUtil.uncapitalize("CAT") = "cAT"Ported over from Apache commons-lang3
str
- the String to uncapitalize, may be nullnull
if null String inputcapitalize(String)
public static String stripEnd(String str, String stripChars)
Strips any of a set of characters from the end of a String.
A null
input String returns null
.
An empty string ("") input returns the empty string.
If the stripChars String is null
, whitespace is
stripped as defined by Character.isWhitespace(char)
.
StringUtils.stripEnd(null, *) = null StringUtils.stripEnd("", *) = "" StringUtils.stripEnd("abc", "") = "abc" StringUtils.stripEnd("abc", null) = "abc" StringUtils.stripEnd(" abc", null) = " abc" StringUtils.stripEnd("abc ", null) = "abc" StringUtils.stripEnd(" abc ", null) = " abc" StringUtils.stripEnd(" abcyx", "xyz") = " abc" StringUtils.stripEnd("120.00", ".0") = "12"Ported over from Apache commons-lang3
str
- the String to remove characters from, may be nullstripChars
- the set of characters to remove, null treated as whitespacenull
if null String inputCopyright © 2006–2022 Apache Software Foundation. All rights reserved.