public class StringUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
EMPTY |
private static int |
PAD_LIMIT
The maximum size to which the padding constant(s) can expand.
|
static String |
SPACE
A String for a space character.
|
| Constructor and Description |
|---|
StringUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isBlank(String str) |
static boolean |
isEmpty(String str) |
static boolean |
isNotBlank(String str) |
static boolean |
isNotEmpty(String str) |
static String |
join(Collection<?> collection,
String delimiter) |
static String |
leftPad(String str,
int size)
Left pad a String with spaces (' ').
|
static String |
leftPad(String str,
int size,
char padChar)
Left pad a String with a specified character.
|
static String |
leftPad(String str,
int size,
String padStr)
Left pad a String with a specified String.
|
static String |
removeEnd(String str,
String remove)
Removes a substring only if it is at the end of a source string,
otherwise returns the source string.
|
static String |
repeat(char ch,
int repeat)
Returns padding using the specified delimiter repeated
to a given length.
|
static String |
repeat(String str,
int repeat)
Repeat a String
repeat times to form a
new String. |
static String |
repeat(String str,
String separator,
int repeat)
Repeat a String
repeat times to form a
new String, with a String separator injected each time. |
static String |
rightPad(String str,
int size)
Right pad a String with spaces (' ').
|
static String |
rightPad(String str,
int size,
char padChar)
Right pad a String with a specified character.
|
static String |
rightPad(String str,
int size,
String padStr)
Right pad a String with a specified String.
|
static boolean |
startsWith(String str,
String prefix) |
static String |
substringAfter(String str,
String separator) |
static String |
toTitleCase(String input)
Returns the string in "title case" (i.e.
|
public static final String EMPTY
private static final int PAD_LIMIT
The maximum size to which the padding constant(s) can expand.
public static final String SPACE
public static boolean isBlank(String str)
public static boolean isNotBlank(String str)
public static boolean isEmpty(String str)
public static boolean isNotEmpty(String str)
public static String join(Collection<?> collection, String delimiter)
public static String leftPad(String str, int size)
Left pad a String with spaces (' ').
The String is padded to the size of size.
StringUtils.leftPad(null, *) = null
StringUtils.leftPad("", 3) = " "
StringUtils.leftPad("bat", 3) = "bat"
StringUtils.leftPad("bat", 5) = " bat"
StringUtils.leftPad("bat", 1) = "bat"
StringUtils.leftPad("bat", -1) = "bat"
str - the String to pad out, may be nullsize - the size to pad tonull if null String inputpublic static String leftPad(String str, int size, char padChar)
Left pad a String with a specified character.
Pad to a size of size.
StringUtils.leftPad(null, *, *) = null
StringUtils.leftPad("", 3, 'z') = "zzz"
StringUtils.leftPad("bat", 3, 'z') = "bat"
StringUtils.leftPad("bat", 5, 'z') = "zzbat"
StringUtils.leftPad("bat", 1, 'z') = "bat"
StringUtils.leftPad("bat", -1, 'z') = "bat"
str - the String to pad out, may be nullsize - the size to pad topadChar - the character to pad withnull if null String inputpublic static String leftPad(String str, int size, String padStr)
Left pad a String with a specified String.
Pad to a size of size.
StringUtils.leftPad(null, *, *) = null
StringUtils.leftPad("", 3, "z") = "zzz"
StringUtils.leftPad("bat", 3, "yz") = "bat"
StringUtils.leftPad("bat", 5, "yz") = "yzbat"
StringUtils.leftPad("bat", 8, "yz") = "yzyzybat"
StringUtils.leftPad("bat", 1, "yz") = "bat"
StringUtils.leftPad("bat", -1, "yz") = "bat"
StringUtils.leftPad("bat", 5, null) = " bat"
StringUtils.leftPad("bat", 5, "") = " bat"
str - the String to pad out, may be nullsize - the size to pad topadStr - the String to pad with, null or empty treated as single spacenull if null String inputpublic static String rightPad(String str, int size)
Right pad a String with spaces (' ').
The String is padded to the size of size.
StringUtils.rightPad(null, *) = null
StringUtils.rightPad("", 3) = " "
StringUtils.rightPad("bat", 3) = "bat"
StringUtils.rightPad("bat", 5) = "bat "
StringUtils.rightPad("bat", 1) = "bat"
StringUtils.rightPad("bat", -1) = "bat"
str - the String to pad out, may be nullsize - the size to pad tonull if null String inputpublic static String rightPad(String str, int size, char padChar)
Right pad a String with a specified character.
The String is padded to the size of size.
StringUtils.rightPad(null, *, *) = null
StringUtils.rightPad("", 3, 'z') = "zzz"
StringUtils.rightPad("bat", 3, 'z') = "bat"
StringUtils.rightPad("bat", 5, 'z') = "batzz"
StringUtils.rightPad("bat", 1, 'z') = "bat"
StringUtils.rightPad("bat", -1, 'z') = "bat"
str - the String to pad out, may be nullsize - the size to pad topadChar - the character to pad withnull if null String inputpublic static String rightPad(String str, int size, String padStr)
Right pad a String with a specified String.
The String is padded to the size of size.
StringUtils.rightPad(null, *, *) = null
StringUtils.rightPad("", 3, "z") = "zzz"
StringUtils.rightPad("bat", 3, "yz") = "bat"
StringUtils.rightPad("bat", 5, "yz") = "batyz"
StringUtils.rightPad("bat", 8, "yz") = "batyzyzy"
StringUtils.rightPad("bat", 1, "yz") = "bat"
StringUtils.rightPad("bat", -1, "yz") = "bat"
StringUtils.rightPad("bat", 5, null) = "bat "
StringUtils.rightPad("bat", 5, "") = "bat "
str - the String to pad out, may be nullsize - the size to pad topadStr - the String to pad with, null or empty treated as single spacenull if null String inputpublic static String repeat(char ch, int repeat)
Returns padding using the specified delimiter repeated to a given length.
StringUtils.repeat('e', 0) = ""
StringUtils.repeat('e', 3) = "eee"
StringUtils.repeat('e', -2) = ""
Note: this method does not support padding with
Unicode Supplementary Characters
as they require a pair of chars to be represented.
If you are needing to support full I18N of your applications
consider using repeat(String, int) instead.
ch - character to repeatrepeat - number of times to repeat char, negative treated as zerorepeat(String, int)public static String repeat(String str, int repeat)
Repeat a String repeat times to form a
new String.
StringUtils.repeat(null, 2) = null
StringUtils.repeat("", 0) = ""
StringUtils.repeat("", 2) = ""
StringUtils.repeat("a", 3) = "aaa"
StringUtils.repeat("ab", 2) = "abab"
StringUtils.repeat("a", -2) = ""
str - the String to repeat, may be nullrepeat - number of times to repeat str, negative treated as zeronull if null String inputpublic static String repeat(String str, String separator, int repeat)
Repeat a String repeat times to form a
new String, with a String separator injected each time.
StringUtils.repeat(null, null, 2) = null
StringUtils.repeat(null, "x", 2) = null
StringUtils.repeat("", null, 0) = ""
StringUtils.repeat("", "", 2) = ""
StringUtils.repeat("", "x", 3) = "xxx"
StringUtils.repeat("?", ", ", 3) = "?, ?, ?"
str - the String to repeat, may be nullseparator - the String to inject, may be nullrepeat - number of times to repeat str, negative treated as zeronull if null String inputpublic static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null.
An empty ("") source string will return the empty string.
A null search string will return the source string.
StringUtils.removeEnd(null, *) = null
StringUtils.removeEnd("", *) = ""
StringUtils.removeEnd(*, null) = *
StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com"
StringUtils.removeEnd("www.domain.com", ".com") = "www.domain"
StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeEnd("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for and remove, may be nullnull if null String inputpublic static String toTitleCase(String input)
null or blank, returns
an empty string. Leading and trailing spaces are trimmed, and multiple internal spaces are condensed.
Examples:
this is a sentence -> This Is A Sentence
allOneWord -> Alloneword
PREVIOUSLY UPPERCASE -> Previously Uppercase
multiple spaces -> Multiple Spacesinput - the input stringCopyright © 2023 Apache NiFi Project. All rights reserved.