public class StringUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_ITEM_SEPARATOR
Default Item Separator
|
static String |
EMPTY
Empty String
|
static String |
LIST_TEMPLATE
Default List Template
|
static String |
NULL
Null String
|
static String |
SPACE
Single Space
|
static char |
TEMPLATE_SEP_CHAR |
| Modifier and Type | Method and Description |
|---|---|
static String |
arrayToString(Object[] array,
String separator)
Converts an array of objects to a string.
|
static String |
arrayToString(Object[] array,
String template,
String defItemValue)
Converts an array of objects to a string.
|
static String |
arrayToString(Object[] array,
String template,
String defItemValue,
boolean ignoreEmpty)
Converts an array of objects to a string.
|
static String |
asString(Object value)
Converts a value to a string.
|
static String |
coalesce(String preferred,
String alternative)
Returns the preferred String if it is not empty
ot the alternative String otherwise.
|
static boolean |
compareEqual(String s1,
String s2)
Compares two Strings with each other - either with or without character case.
|
static boolean |
compareEqual(String s1,
String s2,
boolean ignoreCase)
Compares two Strings with each other - either with or without character case.
|
static boolean |
compareNotEqual(String s1,
String s2)
Compares two Strings with each other - either with or without character case.
|
static boolean |
compareNotEqual(String s1,
String s2,
boolean ignoreCase)
Compares two Strings with each other - either with or without character case.
|
static String |
concat(String... parts)
Assembles a string from several parts
|
static String |
concat(String separator,
Object... params)
Assembles a string from parts with a separator
|
static boolean |
contains(String value,
String substring)
Returns true if the given substring is part of the string provided by value
|
static int |
estimateArrayBufferSize(Object[] array,
int separatorLength)
Estimates the buffer size needed to convert an Array into a String
|
static int |
estimateListBufferSize(Collection<?> list,
int separatorLength)
Estimates the buffer size needed to convert a Collection into a String
|
static int |
indexOfAny(String value,
char... chars)
Returns the first index of any of the given characters in value starting from the beginning
|
static boolean |
isCharBetween(char c,
char beg,
char end)
returns true if the character c is between the characters beg and end
|
static boolean |
isEmpty(String s)
Checks if a string is empty
|
static boolean |
isLower(char c)
returns true if the character c is an upper case character ('a'-'z')
|
static boolean |
isLower(String s,
int count)
returns true if the first count characters of s are all lower case (or other non-case sensitive characters)
|
static boolean |
isNotEmpty(String s)
Checks if a string is not null or empty
|
static boolean |
isNumber(char c)
returns true if the character c is a number digit ('0'-'9')
|
static boolean |
isNumber(String s)
returns true if the string s is a number (contains only the characters 0 to 9)
|
static boolean |
isNumeric(char c,
boolean decimal)
returns true if the character c is a numeric digit ('+' || '-' || '.' || ',' || '0'-'9')
|
static boolean |
isNumeric(String s,
boolean decimal)
returns true if the string s contains only numeric digits ('+' || '-' || '.' || ',' || '0'-'9')
|
static boolean |
isUpper(char c)
returns true if the character c is an upper case character ('A'-'Z')
|
static boolean |
isUpper(String s,
int count)
returns true if the first count characters of s are all upper case (or other non-case sensitive characters)
|
static int |
lastIndexOfAny(String value,
char... chars)
Returns the first index of any of the given characters in value starting from the end
|
static String |
listToString(Collection<?> list,
String separator)
Converts a list (Collection) of objects to a string.
|
static String |
listToString(Collection<?> list,
String template,
String defItemValue)
Converts a list (Collection) of objects to a string.
|
static String |
listToString(Collection<?> list,
String template,
String defItemValue,
boolean ignoreEmpty)
Converts a list (Collection) of objects to a string.
|
static boolean |
notContains(String value,
String substring)
Returns true if the given substring is part of the string provided by value
|
static String |
nullIfEmpty(Object value)
Returns null if the value supplied is null or an empty String.
|
static String |
padLeft(String s,
int size,
char padChar)
Pads a String to the left
|
static String |
padRight(String s,
int size,
char padChar)
Pads a String to the right
|
static String |
remove(String s,
char c)
Removes all occurrences of c from s
|
static String |
remove(String s,
String remove)
Removes all occurrences of remove from s
|
static String |
removeBlanks(String s)
removes all blanks from s
|
static String |
replace(String source,
String find,
String replace)
Replaces all occurrences of find in source by replace.
|
static String |
replaceAll(String s,
String find,
String replace)
Returns a String with all occurrences of
from within orig replaced with to. |
static String |
toLower(String s,
int count)
makes the first n characters of s lower case
|
static String |
toString(Object value)
Converts a value to a string.
|
static String |
toString(Object value,
String defValue)
Converts a value to a string.
|
static String |
toString(Object value,
String listTemplate,
String defValue)
Converts a value to a string.
|
static String |
toUpper(String s,
int count)
makes the first n characters of s upper case
|
static String |
truncate(String s,
int maxChar)
truncates a string to a maximum number of chars
|
static String |
validate(String s)
Validates a given string.
|
static String |
valueOf(Object value)
Converts a value to a string.
|
public static final String EMPTY
public static final String SPACE
public static final String NULL
public static String DEFAULT_ITEM_SEPARATOR
public static String LIST_TEMPLATE
public static char TEMPLATE_SEP_CHAR
public static String toString(Object value, String listTemplate, String defValue)
value - the value to convertlistTemplate - the list template or item separator to be used for arrays and listsdefValue - default value which to return if value is nullpublic static String toString(Object value, String defValue)
value - the value to convertdefValue - default value which to return if value is nullpublic static String toString(Object value)
value - the value to convertpublic static String valueOf(Object value)
value - the value to convertpublic static String asString(Object value)
value - the value to convertpublic static String coalesce(String preferred, String alternative)
preferred - the preferred Stringalternative - the alternative String if the preferred String is not validpublic static String nullIfEmpty(Object value)
value - the value to checkpublic static boolean contains(String value, String substring)
value - the value to checksubstring - the substringpublic static boolean notContains(String value, String substring)
value - the value to checksubstring - the substringpublic static int indexOfAny(String value, char... chars)
value - the value to checkchars - the characters to searchpublic static int lastIndexOfAny(String value, char... chars)
value - the value to checkchars - the characters to searchpublic static String arrayToString(Object[] array, String template, String defItemValue, boolean ignoreEmpty)
array - array of objectstemplate - the list template or item separatordefItemValue - the default item valueignoreEmpty - check value for emptinesspublic static String arrayToString(Object[] array, String template, String defItemValue)
array - array of objectstemplate - the list template or item separatordefItemValue - the default item valuepublic static String arrayToString(Object[] array, String separator)
array - array of objectsseparator - the separator to put between the object stringspublic static int estimateArrayBufferSize(Object[] array, int separatorLength)
array - the arrayseparatorLength - the separator lengthpublic static String listToString(Collection<?> list, String template, String defItemValue, boolean ignoreEmpty)
list - the collection of objectstemplate - the list template or item separatordefItemValue - the default item valueignoreEmpty - check value for emptinesspublic static String listToString(Collection<?> list, String template, String defItemValue)
list - the collection of objectstemplate - the list template or item separatordefItemValue - the default item valuepublic static String listToString(Collection<?> list, String separator)
list - the collection of objectsseparator - the separator to put between the object stringspublic static int estimateListBufferSize(Collection<?> list, int separatorLength)
list - the list to estimateseparatorLength - the separator lengthpublic static String concat(String separator, Object... params)
separator - the separator to put between the object stringsparams - array of objectspublic static String concat(String... parts)
parts - the parts to concatenatepublic static boolean isEmpty(String s)
s - the String to checknullpublic static boolean isNotEmpty(String s)
s - the string to validatepublic static boolean compareEqual(String s1, String s2, boolean ignoreCase)
s1 - the first Strings2 - the second StringignoreCase - whether to ignore the character casing or notpublic static boolean compareEqual(String s1, String s2)
s1 - the first Strings2 - the second Stringpublic static boolean compareNotEqual(String s1, String s2, boolean ignoreCase)
s1 - the first Strings2 - the second StringignoreCase - whether to ignore the character casing or notpublic static boolean compareNotEqual(String s1, String s2)
s1 - the first Strings2 - the second Stringpublic static String validate(String s)
s - the string to validatepublic static String replace(String source, String find, String replace)
source - the original String.find - the String to be replacedreplace - the replacement stringfind in source replaced by replacepublic static String replaceAll(String s, String find, String replace)
from within orig replaced with to.
If orig contains no occurrences of from, or if from is equal to
to,orig itself is returned rather than a copy being made. If orig is null,
null is returned.s - the original String.find - the String to be replacedreplace - the replacement stringfind in source replaced by replacepublic static String remove(String s, String remove)
s - the source stringremove - the string to removepublic static String remove(String s, char c)
s - the source stringc - the character to removepublic static String removeBlanks(String s)
s - the source stringpublic static boolean isCharBetween(char c,
char beg,
char end)
c - the source characterbeg - the lower end characterend - the higher end characterpublic static boolean isNumber(char c)
c - the source characterpublic static boolean isNumber(String s)
s - the source stringpublic static boolean isNumeric(char c,
boolean decimal)
c - the source characterdecimal - flag to indicate whether the decimal and grouping separators ('.' || ',') are allowedpublic static boolean isNumeric(String s, boolean decimal)
s - the source stringdecimal - flag to indicate whether the decimal and grouping separators ('.' || ',') are allowedpublic static boolean isUpper(char c)
c - the characterpublic static boolean isUpper(String s, int count)
s - the source stringcount - number of characters to checkpublic static boolean isLower(char c)
c - the characterpublic static boolean isLower(String s, int count)
s - the source stringcount - number of characters to checkpublic static String toUpper(String s, int count)
s - the source stringcount - the number of characters to convertpublic static String toLower(String s, int count)
s - the source stringcount - the number of characters to convertpublic static String truncate(String s, int maxChar)
s - the source stringmaxChar - the maximum number of charspublic static String padLeft(String s, int size, char padChar)
s - the string to padsize - the desired sizepadChar - the padding charCopyright © 2008–2023 Apache Software Foundation. All rights reserved.