public class StringUtils extends Object
| Constructor and Description |
|---|
StringUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isEmpty(String str)
Checks if a String is empty ("") or null.
|
static String |
padLeft(String str,
int size)
Left pad a String with spaces (' ').
|
static String |
padLeft(String str,
int size,
char padChar)
Left pad a String with a specified character.
|
static String |
padLeft(String str,
int size,
String padStr)
Left pad a String with a specified String.
|
static String |
padRight(String string,
int size)
Right-pad the provided String with empty spaces.
|
static String |
padRight(String inputString,
int size,
char paddingChar)
Right-pad a String with a configurable padding character.
|
public static String padLeft(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 padLeft(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 padLeft(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 boolean isEmpty(String str)
Checks if a String is empty ("") or null.
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().
str - the String to check, may be nulltrue if the String is empty or nullpublic static String padRight(String inputString, int size, char paddingChar)
inputString - The String to pad. A null String will be treated like
an empty String.size - Pad String by the number of characters.paddingChar - The character to pad the String with.