public enum StringUtils extends Enum<StringUtils>
String manipulation utilities.
Modifier and Type | Method and Description |
---|---|
static boolean |
contains(String s,
String searchStr)
Return true if the string contains the search string, or false if either is null.
|
static boolean |
containsIgnoreCase(String s,
String searchStr)
Return true if the string contains the search string, ignoring case, or false if either is
null.
|
static boolean |
equalsIgnoreCase(String s1,
String s2)
Null-safe case-insensitive equals.
|
static boolean |
isAllBlank(String... strings)
Returns true if all of the strings passed in are blank, as determined by isBlank.
|
static boolean |
isAnyBlank(String... strings)
Returns true if any of the strings passed in are blank, as determined by isBlank.
|
static boolean |
isBlank(String s)
Return true if this string is either null or just whitespace.
|
static boolean |
isEmpty(String s)
Returns true if the string is empty.
|
static boolean |
isNoneBlank(String... strings)
Returns true if none of the strings passed in are blank, as determined by isBlank.
|
static boolean |
isNotBlank(String s)
Return true if this string is not null and not just whitespace.
|
static boolean |
isNotEmpty(String s)
Returns true if the string is not empty.
|
static String |
join(Collection<?> objects,
String delimiter)
Join the collection of objects to a string.
|
static String |
left(String s,
int length)
Return the first length characters of the string.
|
static int |
length(String s)
Return the length of the string, or 0 if the string is null.
|
static String |
random(int length,
String allowed)
Returns a string of the requested length, made up of characters from the allowed string.
|
static String |
randomAlphabetic(int length)
Returns a string of random alphabetic characters of the requested length.
|
static String |
randomAlphabetic(int minLengthInclusive,
int maxLengthExclusive)
Returns a string of random alphabetic characters at least minLengthInclusive characters and
less than maxLengthExclusive characters long.
|
static String |
randomPrint(int length)
Returns a string of random printable characters of the requested length.
|
static String |
randomPrint(int minLengthInclusive,
int maxLengthExclusive)
Returns a string of random printable characters at least minLengthInclusive characters and
less than maxLengthExclusive characters long.
|
static String |
repeat(String substring,
int count)
Repeat the substring count times.
|
static String |
replace(String template,
Map<String,String> replacements,
String prefix,
String suffix)
Replace the placeholders in the template with the values in the replacement mapping.
|
static String |
upperCase(String s)
Returns the string in uppercase, or null if it was null
|
static StringUtils |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static StringUtils[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static StringUtils[] values()
for (StringUtils c : StringUtils.values()) System.out.println(c);
public static StringUtils valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static boolean isBlank(String s)
Return true if this string is either null or just whitespace.
s
- the stringpublic static boolean isNotBlank(String s)
Return true if this string is not null and not just whitespace.
s
- the stringpublic static String join(Collection<?> objects, String delimiter)
Join the collection of objects to a string.
Objects that are null are represented by the empty string.
objects
- collection of objectsdelimiter
- delimiter between the objectspublic static String replace(String template, Map<String,String> replacements, String prefix, String suffix)
Replace the placeholders in the template with the values in the replacement mapping.
template
- template stringreplacements
- map from key to replacement valueprefix
- prefix of the placeholdersuffix
- suffix of the placeholderpublic static String randomPrint(int minLengthInclusive, int maxLengthExclusive)
Returns a string of random printable characters at least minLengthInclusive characters and less than maxLengthExclusive characters long.
The characters have ASCII codes ranging from 32 to 125 (both inclusive) and include spaces.
minLengthInclusive
- minimum length (inclusive)maxLengthExclusive
- maximum length (exclusive)public static String randomPrint(int length)
Returns a string of random printable characters of the requested length.
The characters have ASCII codes ranging from 32 to 125 (both inclusive) and include spaces.
length
- length in characterspublic static String randomAlphabetic(int minLengthInclusive, int maxLengthExclusive)
Returns a string of random alphabetic characters at least minLengthInclusive characters and less than maxLengthExclusive characters long.
The characters range from 'A' - 'Z' or from 'a' - 'z' (all inclusive).
minLengthInclusive
- minimum length (inclusive)maxLengthExclusive
- maximum length (exclusive)public static String randomAlphabetic(int length)
Returns a string of random alphabetic characters of the requested length.
The characters range from 'A' - 'Z' or from 'a' - 'z' (all inclusive).
length
- length in characterspublic static String random(int length, String allowed)
Returns a string of the requested length, made up of characters from the allowed string.
length
- length in charactersallowed
- string with allowed characterspublic static boolean isAnyBlank(String... strings)
Returns true if any of the strings passed in are blank, as determined by isBlank.
strings
- strings to checkpublic static boolean isNoneBlank(String... strings)
Returns true if none of the strings passed in are blank, as determined by isBlank.
strings
- strings to checkpublic static boolean isAllBlank(String... strings)
Returns true if all of the strings passed in are blank, as determined by isBlank.
strings
- strings to checkpublic static boolean isNotEmpty(String s)
Returns true if the string is not empty.
s
- string to checkpublic static boolean isEmpty(String s)
Returns true if the string is empty.
s
- string to checkpublic static String upperCase(String s)
Returns the string in uppercase, or null if it was null
s
- string to convert to uppercasepublic static String left(String s, int length)
Return the first length characters of the string.
s
- stringlength
- number of characterspublic static int length(String s)
Return the length of the string, or 0 if the string is null.
s
- stringpublic static boolean containsIgnoreCase(String s, String searchStr)
Return true if the string contains the search string, ignoring case, or false if either is null.
s
- stringsearchStr
- substring to search forpublic static boolean equalsIgnoreCase(String s1, String s2)
Null-safe case-insensitive equals.
s1
- first strings2
- second stringpublic static boolean contains(String s, String searchStr)
Return true if the string contains the search string, or false if either is null.
s
- stringsearchStr
- substring to search forCopyright © 2016–2024. All rights reserved.