public class StringUtil extends Object
String related methods.| Constructor and Description |
|---|
StringUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
appendObjectsAsString(StringBuffer buffer,
List data)
Appends the entries in the specified
List as strings
with a terminating "\n" after each row. |
static void |
appendTabs(StringBuffer buffer,
int number)
Appends number tabs (\t) to the buffer.
|
static int |
compare(String string1,
String string2)
Compares two strings and returns the last
index where the two string are equal.
|
static int |
countMatches(String string,
String other)
Returns how many times
string contains
other. |
static String |
emptyStringToNull(String string)
Returns
null, if the specified string is null or
the empty string. |
static String |
fieldToString(String fieldName,
Object field)
Helper method for
toString() implementations. |
static boolean |
isEmptyOrNull(String string)
Returns if the specified string is
null or
the empty string. |
static String |
lowerCase(String string,
int index)
Converts the character at the specified index to
lowercase and returns the resulting string.
|
static String |
lowerCase(String string,
int startIndex,
int endIndex)
Converts the character in the specified index range to
lowercase and returns the resulting string.
|
static boolean |
matchesContains(String source,
String target,
boolean caseSensitive)
Returns if
source contains target,
ignoring case, if caseSensitive is false. |
static boolean |
matchesExact(String source,
String target,
boolean caseSensitive)
Returns if the specified strings are equal, ignoring
case, if
caseSensitive is false. |
static boolean |
matchesPerl5(String source,
String target,
boolean caseSensitive)
Returns if the regular expression
target matches
source, ignoring case, if caseSensitive
is false. |
static String |
replaceAll(String source,
String match,
String replacement)
Replaces all occurrences of
match in
source with replacement. |
static String[] |
split(String string,
String delim,
boolean doTrim)
Splits a string into tokens.
|
public static boolean isEmptyOrNull(String string)
null or
the empty string.string - the stringtrue if the specified string is null or
the empty string, false otherwisepublic static String emptyStringToNull(String string)
null, if the specified string is null or
the empty string. Returns the specified string otherwise.string - the stringnull if the specified string is null or
the empty string, the specified string otherwisepublic static String replaceAll(String source, String match, String replacement)
match in
source with replacement.source - the source stringmatch - the string that is searchedreplacement - the replacement stringIllegalArgumentException - if any argument is null or
if match is the empty stringpublic static int compare(String string1, String string2)
string1 - the first stringstring2 - the second stringpublic static String lowerCase(String string, int index)
string - the string to convertindex - the index where the character is set to lowercaseIndexOutOfBoundsException - if the index is out of
rangepublic static String lowerCase(String string, int startIndex, int endIndex)
string - the string to convertstartIndex - the index to start, inclusiveendIndex - the index to end, exclusiveIndexOutOfBoundsException - if the index is out of
rangepublic static String fieldToString(String fieldName, Object field)
toString() implementations.
Returns a string "field name: value". Handles
null values, collections and arrays. If the
field is a collection or an array, the returned string will
be:"field name 0: value0\nfield name 1: value1"fieldName - the field namefield - the field valuetoString() implementationspublic static void appendObjectsAsString(StringBuffer buffer, List data)
List as strings
with a terminating "\n" after each row.buffer - the bufferdata - the List with the datapublic static void appendTabs(StringBuffer buffer, int number)
buffer - the buffernumber - the number of tabs to appendpublic static String[] split(String string, String delim, boolean doTrim)
StringTokenizer
except that empty tokens are recognized and added as null.
With a delimiter of ";" the string
"a;;b;c;;" will split into
["a"] [null] ["b"] ["c"] [null].string - the Stringdelim - the delimiterdoTrim - should each token be trimmedpublic static int countMatches(String string, String other)
string contains
other.string - the string to searchother - the string that is searchedpublic static boolean matchesExact(String source, String target, boolean caseSensitive)
caseSensitive is false.source - the source Stringtarget - the target StringcaseSensitive - is the comparison case sensitivetrue if the strings matches
false otherwisepublic static boolean matchesContains(String source, String target, boolean caseSensitive)
source contains target,
ignoring case, if caseSensitive is false.source - the source Stringtarget - the target StringcaseSensitive - is the comparison case sensitivetrue if the strings matches
false otherwisepublic static boolean matchesPerl5(String source, String target, boolean caseSensitive)
target matches
source, ignoring case, if caseSensitive
is false.source - the source Stringtarget - the target StringcaseSensitive - is the comparison case sensitivetrue if the strings matches
false otherwiseCopyright © 2003-2014. All Rights Reserved.