public final class StringUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
EMPTY
Instance of the empty string
|
static String[] |
EMPTY_ARRAY
Instance of the empty array of string
|
| Modifier and Type | Method and Description |
|---|---|
static String |
buildSpace(int spaces)
Generate space
|
static String |
capitalize(String text)
Capitalize characters in string, merged from StringUtils.capitalize [modules - commons-lang:commons-lang3]
|
static boolean |
containsCharacter(String text,
char... characters)
Checks if the specified text contains any character from the specified array
|
static boolean |
containsOtherCharacters(String text,
char[]... characters)
Checks if the specified text contains other characters than these from the specified array
|
static boolean |
containsSpecialCharacters(String text)
Checks if the specified text contains character other than letter or digit
|
static int |
countOccurrences(String text,
String element)
Amount of the occurrences of the specified text in string
|
static String |
extractParagraph(String str)
Extracts paragraph/indentation from the beginning of the text
|
static boolean |
isEmpty(String text)
Checks if the specified text is null or empty
|
static String |
isEmpty(String text,
String exceptionMessage)
Checks if the specified text is null or empty, throw exception if it is
|
static boolean |
isNumber(String str)
Check if the specified string can be parsed as a number
Allowed characters:
0-9 - digits
x - hexadecimal
|
static String |
join(String... strings)
Join string into the one string
|
static int |
lastIndexOf(String text,
String element,
int toIndex)
Returns the index within this string of the last occurrence of the specified substring
|
static int |
lastIndexOfBefore(String text,
String element,
int occurrences)
Last index of the element with given amount of last occurrences to ignore
|
static String |
repeated(int repetitions,
String... elements) |
static String |
replace(String text,
String searchString,
String replacement)
Faster alternative to String#replace
|
static String |
replaceFirst(String text,
String pattern,
String replacement)
Replace the first occurrence of the specified pattern in the text
|
static String |
replaceFirst(String text,
String pattern,
String replacement,
int start)
Replace the first occurrence of the specified pattern in the text
|
static String |
replaceRespectively(String text,
String pattern,
String... values)
Replaces respectively substring of this string that matches the literal target sequence with the specified literal replacement sequence.
|
static String |
replaceRespectivelyAndSoftly(String text,
String pattern,
String... values)
Replaces respectively substring of this string that matches the literal target sequence with the specified literal replacement sequence.
|
static String[] |
split(String text,
String delimiter)
Split text by the specified delimiter (without regex)
|
static String[] |
splitFirst(String text,
String delimiter)
Split text by the specified delimiter, but only once (to the first occurrence of the specified delimiter)
|
static boolean |
startsWith(String text,
Predicate<char[]> filter)
Check how the specified text starts
|
static String |
toString(@Nullable Object object)
Object to string with array support
|
static String |
trimEnd(String text)
Trim the of end of the specified text
|
static String |
trimStart(String text)
Trim the beginning of the text
|
public static final String EMPTY
public static final String[] EMPTY_ARRAY
public static String[] splitFirst(String text, String delimiter)
text - the text to splitdelimiter - the delimiter to search forpublic static String[] split(String text, String delimiter)
text - the text to splitdelimiter - the delimiting textpublic static int lastIndexOfBefore(String text, String element, int occurrences)
text - the text to search inelement - the element to search foroccurrences - amount of occurrences to ignore before the element to search forpublic static int lastIndexOf(String text, String element, int toIndex)
text - the text to searchelement - the substring to search fortoIndex - the previous last indexpublic static String replace(String text, String searchString, String replacement)
text - the text to search and replace insearchString - the text to search forreplacement - the text to replace withpublic static String replaceFirst(String text, String pattern, String replacement)
text - the text to search and replace inpattern - the text to search forreplacement - the text to replace withpublic static String replaceFirst(String text, String pattern, String replacement, int start)
text - the text to search and replace inpattern - the text to search forreplacement - the text to replace withstart - position to start searching forpublic static String replaceRespectively(String text, String pattern, String... values)
text - The sequence of char values to be replace replacement – The replacement sequence of char valuespattern - The pattern to searchvalues - The replacement sequencesIllegalArgumentException - if the amount of patterns is different than the amount of valuespublic static String replaceRespectivelyAndSoftly(String text, String pattern, String... values)
text - The sequence of char values to be replace replacement – The replacement sequence of char valuespattern - The pattern to searchvalues - The replacement sequencespublic static String capitalize(String text)
text - the string to capitalize, may be nullnull if null string inputpublic static boolean startsWith(String text, Predicate<char[]> filter)
text - the text to checkfilter - conditionpublic static String trimStart(String text)
text - the text to trimpublic static String trimEnd(String text)
text - the text to trimpublic static String extractParagraph(String str)
str - a string to searchpublic static String buildSpace(int spaces)
spaces - number of spacespublic static int countOccurrences(String text, String element)
text - the string to search inelement - the string to search forpublic static boolean containsCharacter(String text, char... characters)
text - a string to searchcharacters - searched characterspublic static boolean containsSpecialCharacters(String text)
text - the string to search inpublic static boolean containsOtherCharacters(String text, char[]... characters)
text - the string to search inpublic static String join(String... strings)
strings - strings to joinpublic static String toString(@Nullable @Nullable Object object)
object - the object to stringifypublic static boolean isNumber(String str)
str - string to checkpublic static String isEmpty(String text, String exceptionMessage)
text - to checkexceptionMessage - the message is used by IllegalArgumentExceptionpublic static boolean isEmpty(String text)
text - to checkCopyright © 2020. All rights reserved.