public class StringUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
EMPTY
The empty String
"" . |
static String |
SPACE
A String for a space character.
|
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
isBlank(String s) |
static boolean |
isEmpty(CharSequence cs) |
static String |
joinWith(String delimiter,
List<String> lines) |
static String |
leftPad(String str,
int size,
char padChar) |
static String |
leftPad(String str,
int size,
String padStr)
Left pad a String with a specified 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. |
public static final String EMPTY
""
.public static final String SPACE
public static boolean isEmpty(CharSequence cs)
public static boolean isBlank(String s)
public 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 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 char
s 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 inputCopyright © 2007–2022 The Apache Software Foundation. All rights reserved.