public final class StringUtils
extends java.lang.Object
try {
// ...
} catch (Exception ex) {
String ex = StringUtils.getStackTrace(ex);
// or
String ex[] = StringUtils.getStackTraceArray(ex);
// ...
}
String s = "Mary had a little lamb";
String[] toks = StringUtils.split(s, " \t");
String s[] =
{ "Mary", "had", "a", "little", "lamb" };
String ret = StringUtils.concat(s, " ");
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CRLF
Contains the line.separator value
|
static char[] |
EMPTY_CHAR_ARRAY |
static java.lang.String |
EMPTY_STRING |
static java.lang.String[] |
EMPTY_STRING_ARRAY |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
addWhitespaceBetweenCharacters(java.lang.String s)
Add whitespace between characters in a string
|
static java.lang.String[] |
append(java.lang.String[] origin,
java.lang.String s)
Adds a value to the end of the array.
|
static java.util.Map<java.lang.String,java.lang.String> |
asPropertyMap(java.lang.String s)
Loads the content of the string as a property map.
|
static java.util.Map<java.lang.String,java.lang.String> |
asPropertyMap(java.lang.String s,
java.util.Map<java.lang.String,java.lang.String> target)
Loads the content of the string as a property map.
|
static java.lang.String |
capitalize(java.lang.String s) |
static int |
compareTo(java.lang.String left,
java.lang.String right)
Compares two string including nulls
|
static int |
compareTo(java.lang.String left,
java.lang.String right,
boolean ignoreCase)
Compares two string including nulls
|
static java.lang.String |
concat(java.util.Collection<java.lang.String> strings,
char separator) |
static java.lang.String |
concat(java.util.Collection<java.lang.String> strings,
java.lang.String delim)
This method concatenates a Collection of strings into a single string,
using the given delimiter as a filler between the array elements.
|
static java.lang.String |
concat(java.lang.Object[] objects,
java.lang.String delim)
This method concatenates an array of strings into a single string, using
the given delimiter as a filler between the array elements.
|
static java.lang.String |
concat(java.lang.String[] strings,
java.lang.String delim)
This method concatenates an array of strings into a single string, using
the given delimiter as a filler between the array elements.
|
static boolean |
contains(java.util.Collection<java.lang.String> collection,
java.lang.String s)
Returns true, if the string is equal to at least one of the strings
within the provided collection.
|
static boolean |
contains(java.util.Iterator<java.lang.String> itr,
java.lang.String s)
Returns true if the Iterator contains the specified string.
|
static boolean |
contains(java.lang.String[] arr,
java.lang.String s)
Returns true, if the string is equal to at least one of the strings
within the provided array.
|
static boolean |
contains(java.lang.String source,
java.lang.String search)
Checks whether source string contains search
|
static boolean |
contains(java.lang.String source,
java.lang.String search,
boolean caseSensitive)
Checks whether source string contains search
|
static boolean |
contains(java.lang.String str,
java.lang.String token,
java.lang.String delim,
boolean ignoreCase) |
static boolean |
containsIgnoreCase(java.lang.String[] arr,
java.lang.String s)
Returns true, if the string is equal to at least one of the
strings(ignore case) within the provided array.
|
static boolean |
containsIgnoreCase(java.lang.String source,
java.lang.String search)
Checks whether source string contains search
|
static boolean |
containsNull(java.lang.String[] arr)
Returns true, if the array contains a null element
|
static boolean |
containsOnly(java.util.Iterator<java.lang.String> itr,
java.lang.String s)
Returns true if the Iterators contains only values of specified string.
|
static boolean |
containsOnly(java.util.List<java.lang.String> list,
java.lang.String s)
Returns true if the List contains only values of the specified string.
|
static boolean |
containsWhitespace(java.lang.String s)
Returns true if the string contains at least one whitespace character.
|
static boolean |
containsWildCard(java.lang.String s)
Returns true if the string contains a question mark or an asterix.
|
static java.lang.String[] |
copy(java.lang.String[] s)
Copy a string array.
|
static java.lang.String |
cut(java.lang.String s,
int max)
Cuts the length of the string if it is longer than max.
|
static java.lang.String |
defaultIfEmpty(java.lang.String value,
java.lang.String fallback)
Returns the string back if blank returns the fallback
|
static java.lang.String |
emptyIfNull(java.lang.String s) |
static java.lang.String[] |
emptyIfNull(java.lang.String[] in) |
static boolean |
equals(java.lang.String left,
java.lang.String right)
Checks equality of two strings
|
static boolean |
equalsIgnoreCase(java.lang.String left,
java.lang.String right)
Checks equality of two strings ignoring case
|
static java.lang.String |
escapeJavascript(java.lang.String str)
Removes javascript code wrapped in script tag
|
static java.lang.String |
escapeJavaString(java.lang.String s)
Escapes non printables and other characters in a Java string so that it
is syntactically correct.
|
static java.lang.String |
escapeJavaStringForJSON(java.lang.String s)
Escapes non valid characters in a Java string so that it is syntactically
correct according to JSON specification.
|
static java.lang.String |
escapeScriptTags(java.lang.String str)
Remove script tags from text
|
static java.lang.String |
escapeSpecial(java.lang.String s)
Deprecated.
What's so special about it??? Use
escapeJavaString(String) instead... |
static java.lang.String |
escapeString(java.lang.String source)
Deprecated.
Use
escapeXML(String) instead. |
static java.lang.String |
escapeXML(java.lang.String source)
Escapes the string according to XML escaping rules and returns the
result.
|
static void |
escapeXML(java.lang.String source,
java.lang.StringBuffer out)
Deprecated.
As of 2010.1.0 use the
escapeXML(String, StringBuilder) instead. |
static void |
escapeXML(java.lang.String source,
java.lang.StringBuilder out)
Escapes the string according to XML escaping rules and appends the result
to the specified buffer.
|
static void |
escapeXML(java.lang.String source,
java.io.Writer out)
Escapes the string according to XML escaping rules and writes the result
to the specified Writer.
|
static java.lang.String |
escapeXMLChar(int ch)
Escapes a single character and returns the escaped string.
|
static void |
escapeXMLChar(java.lang.StringBuffer target,
int ch)
Deprecated.
As of 2010.1.0 use the
escapeXMLChar(StringBuilder, int) instead. |
static void |
escapeXMLChar(java.lang.StringBuilder target,
int ch)
Escapes a single character into the specified StringBuilder.
|
static java.lang.String |
getEntityRef(int ch)
Encode special XML characters into the equivalent character references.
|
static java.lang.String |
getEOL()
Returns the end-of-line characters used on the current platform.
|
static java.lang.String |
getStackTrace(java.lang.Throwable ex)
This method outputs an exception stack-trace to a string
|
static java.lang.String[] |
getStackTraceArray(java.lang.Throwable ex)
This method outputs an exception stack-trace to an array of strings, each
element containing one line of the stack-trace
|
static java.lang.String[] |
getUniqueValues(java.lang.String[] arr)
Returns the unique values within the provided array
|
static int |
indexOf(java.lang.String[] arr,
java.lang.String s)
Returns the index of the string within the array.
|
static java.lang.String[] |
intersection(java.lang.String[] array1,
java.lang.String[] array2)
Returns all (unique) strings that both are in array1 AND in array2.
|
static boolean |
isBlank(java.lang.String s)
Shorter variant of
isOnlyWhitespaceOrEmpty(String) |
static boolean |
isBoolean(java.lang.String s)
Returns true if the string represents the text "true" or "false" (case
sensitive match)
|
static boolean |
isEmpty(java.lang.String[] values)
Checks if a string array is empty (or null)
|
static boolean |
isFalseOrNo(java.lang.String s) |
static boolean |
isFalseOrNo(java.lang.String s,
boolean defaultValue) |
static boolean |
isInteger(java.lang.String s) |
static boolean |
isJavaClassName(java.lang.String s)
Checks if a given string is a valid java class name.
|
static boolean |
isJavaIdentifier(java.lang.String identifier)
Check if a string is a valid Java identifier.
|
static boolean |
isNotBlank(java.lang.String s) |
static boolean |
isNullOrEqualToNull(java.lang.String s)
Checks if a string is null or equal to "null".
|
static boolean |
isNumber(java.lang.String s) |
static boolean |
isOnlyWhitespaceOrEmpty(java.lang.String s)
Returns true if the string only contains whitespace characters, is empty
or if it is null.
|
static boolean |
isTrue(java.lang.String s) |
static boolean |
isTrue(java.lang.String s,
boolean defaultValue) |
static boolean |
isTrueOrYes(java.lang.String s) |
static boolean |
isTrueOrYes(java.lang.String s,
boolean defaultValue) |
static java.lang.String |
joinListValues(java.util.List<java.lang.String> items,
java.lang.String sep)
Join the Item present in list
|
static java.lang.String |
leftpad(java.lang.String s,
int len,
char c)
Left pads the string with the specified charater, as many times needed in
order to get the specified length of the string.
|
static boolean |
match(java.lang.String s,
java.lang.String pattern)
Performs a match between the string and the pattern.
|
static boolean |
matchAny(java.lang.String str,
java.lang.String[] patterns)
Performs a match between the string and the patterns.
|
static boolean |
matchAnyIgnoreCase(java.lang.String str,
java.lang.String[] patterns)
Performs a match between the string and the patterns ignoring case.
|
static boolean |
matchIgnoreCase(java.lang.String string,
java.lang.String pattern)
Performs a match between the string and the pattern ignoring case.
|
static java.lang.String |
next(java.util.Iterator<java.lang.String> itr)
Returns the next string of the iterator
|
static java.lang.String |
next(java.util.Iterator<java.lang.String> itr,
java.lang.String fallback)
Returns the next string of the iterator
|
static java.lang.String |
normalizeSpace(java.lang.String str)
Trim white space characters from both sides of the specified string and
redundant white space characters from within the string.
|
static java.lang.String |
notNull(java.lang.String s)
Checks if the argument is null and if so returns an empty string.
|
static java.lang.String |
nullIfEmpty(java.lang.String s) |
static java.util.Map<java.lang.String,java.lang.String> |
parseArgs(java.lang.String inputString)
Parses a string into an argument map.
|
static java.util.Map<java.lang.String,java.lang.String> |
parseArgs(java.lang.String inputString,
char argSeparator,
boolean caseInsensitiveKeys) |
static java.util.Map<java.lang.String,java.lang.String> |
parseArgs(java.lang.String inputString,
char valueSeparator,
char argSeparator,
boolean caseInsensitiveKeys,
boolean escapeBackslashes)
Parses a string into an argument map.
|
static boolean |
parseBoolean(java.lang.String s,
boolean defaultValue)
Parses a value into a boolean.
|
static double |
parseDouble(java.lang.String s,
double defaultValue)
Safe parsing of a string to a double
|
static int |
parseInt(java.lang.String s,
int i)
Safe parsing of a string to an integer.
|
static long |
parseLong(java.lang.String s,
long defaultValue)
Safe parsing of a string to an long.
|
static java.lang.String |
removeAllWhitespaces(java.lang.String s)
Removes all whitespaces from a string.
|
static java.util.Collection<java.lang.String> |
removeBlanks(java.util.Collection<java.lang.String> input)
Removes blank strings from the given list and returns new list
|
static java.lang.String |
removeBreakAtEnd(java.lang.String s)
Removes the CRLF at the end of the specified string.
|
static java.lang.String |
removeConsecutiveWhitespaces(java.lang.String s)
Removes any multiple occurence of consecutive whitespaces.
|
static java.lang.String |
removeLeadingCharacter(java.lang.String str,
char removeChar)
Removes the specified leading character.
|
static java.lang.String[] |
removeNulls(java.lang.String[] in)
Removes null items from the string array and returns either the same
array if no items were null, or a new array containing only the non-null
items from the source array.
|
static java.lang.String |
removeTrailingCharacter(java.lang.String str,
char removeChar)
Removes the specified trailing character.
|
static java.lang.String |
replace(java.lang.String orig,
java.lang.String pattern,
java.lang.String newvalue)
This method replaces the occurrences of a given substring with another
string returning the converted string
|
static java.lang.String[] |
reverse(java.lang.String[] arr)
Reverses the item within an array...
|
static java.lang.String |
rightpad(java.lang.String s,
int len,
char c)
Right pads the string with the specified charater, as many times needed
in order to get the specified length of the string.
|
static void |
sort(java.util.List<java.lang.String> s)
Sort string values in the specified list.
|
static void |
sort(java.lang.String[] s)
Sort string values in the specified array.
|
static java.lang.String[] |
split(java.lang.String str)
This method splits a string into an array of substrings
|
static java.lang.String[] |
split(java.lang.String str,
java.lang.String delim)
This method splits a string into an array of substrings
|
static java.lang.String[] |
splitAndEscape(java.lang.String str,
java.lang.String delim)
Splits the string using the
split(String, String) method and
escapes each entry in the array using the
escapeJavaString(String) method. |
static java.util.List<java.lang.String> |
splitToList(java.lang.String s,
java.lang.String delimiter)
Split the string into a list.
|
static void |
splitToList(java.lang.String s,
java.lang.String delim,
java.util.List<java.lang.String> list)
Split the string and add the substrings to the specified list.
|
static boolean |
startsWith(java.lang.String source,
java.lang.String prefix)
Checks whether source string starts with prefix
|
static boolean |
startsWith(java.lang.String source,
java.lang.String prefix,
boolean caseSensitive)
Checks whether source string starts with prefix
|
static boolean |
startsWithIgnoreCase(java.lang.String source,
java.lang.String prefix)
Checks whether source string starts with prefix
|
static java.lang.String |
stripNonValidXMLCharacters(java.lang.String source)
This method ensures that the output String has only valid XML unicode
characters as specified by the XML 1.0 standard.
|
static java.lang.String[] |
subarr(java.lang.String[] arr,
int start,
int len)
Returns a sub array from the given array starting at start and
ending at start+len
|
static java.lang.String[] |
toArray(matrix.util.StringList sl)
Converts the StringList into an array of strings.
|
static java.lang.String |
toEnumConstant(java.lang.String name)
To enum constant name format
|
static java.util.Enumeration<java.lang.String> |
toEnumeration(java.util.StringTokenizer st)
Converts a StringTokenizer to an Enumeration of Strings.
|
static java.lang.String |
toEnumLower(java.lang.String name)
To enum value name format
|
static java.util.List<java.lang.String> |
toList(matrix.util.StringList data) |
static java.lang.String |
toLowerCase(java.lang.String s) |
static java.lang.String |
toString(java.lang.String value,
java.lang.String fallback)
Returns the string back if blank returns the fallback
|
static java.lang.String[] |
toStringArray(java.util.Collection<java.lang.String> c)
Convert the specified collection into an array of strings.
|
static java.lang.String[] |
toStringArray(java.lang.Object[] array)
Converts any object array to an array of strings.
|
static java.lang.String[] |
toStringArray(java.lang.String s) |
static matrix.util.StringList |
toStringList(java.util.Collection<java.lang.String> c) |
static matrix.util.StringList |
toStringList(java.lang.String... a) |
static java.lang.String |
toUpperCase(java.lang.String s) |
static java.lang.String |
trim(java.lang.String str) |
static java.lang.String |
trim(java.lang.String str,
char removeChar)
Trims the specified string from any specified character
|
static java.lang.String |
trimLeft(java.lang.String str)
Trim white space characters from the left of the specified string.
|
static java.lang.String |
trimRight(java.lang.String str)
Trim white space characters from the right of the specified string.
|
static java.lang.String |
trimToEmpty(java.lang.String s) |
static java.lang.String |
trimToNull(java.lang.String s) |
static java.lang.String |
unquote(java.lang.String str)
Removes the trailing and ending quote (or double quote) character.
|
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static final java.lang.String EMPTY_STRING
public static final char[] EMPTY_CHAR_ARRAY
public static final java.lang.String CRLF
public static java.lang.String getStackTrace(java.lang.Throwable ex)
ex - the exceptionpublic static java.lang.String[] getStackTraceArray(java.lang.Throwable ex)
ex - the exceptionpublic static java.lang.String[] append(java.lang.String[] origin,
java.lang.String s)
origin - The origin array of strings. if null, a new string array
will be created.s - The string to append to the array.public static java.lang.String[] intersection(java.lang.String[] array1,
java.lang.String[] array2)
array1 - An array of stringsarray2 - Another arraypublic static java.lang.String[] split(java.lang.String str)
str - the string to splitpublic static java.lang.String[] split(java.lang.String str,
java.lang.String delim)
str - the string to splitdelim - a string containing all tokes used for splittingpublic static java.lang.String concat(java.lang.String[] strings,
java.lang.String delim)
strings - an array of stringsdelim - a delimiter string that is put between the former string
elements during the concatinationpublic static java.lang.String concat(java.util.Collection<java.lang.String> strings,
char separator)
strings - A collection of string instanceseparator - A character used for separating the itemspublic static java.lang.String concat(java.lang.Object[] objects,
java.lang.String delim)
objects - an array of objectsdelim - a delimiter string that is put between the former string
elements during the concatinationpublic static java.lang.String concat(java.util.Collection<java.lang.String> strings,
java.lang.String delim)
strings - an array of stringsdelim - a delimiter string that is put between the former string
elements during the concatenationpublic static java.lang.String removeBreakAtEnd(java.lang.String s)
s - the string to remove the CRLF at the end from.public static java.lang.String removeTrailingCharacter(java.lang.String str,
char removeChar)
str - removeChar - public static java.lang.String removeConsecutiveWhitespaces(java.lang.String s)
For example, a string containing following text: (the whitespace is marked).
A TEXT WITH SOME SPACES .TEXT ^^ ^^^^^^^^^ ^^^^ ^ ^^^Will after calling this method be:
A TEXT WITH SOME SPACES .TEXT ^ ^ ^ ^ ^
s - public static java.lang.String removeLeadingCharacter(java.lang.String str,
char removeChar)
str - removeChar - public static boolean containsWhitespace(java.lang.String s)
public static java.lang.String replace(java.lang.String orig,
java.lang.String pattern,
java.lang.String newvalue)
orig - the original stringpattern - the pattern to replacenewvalue - the new value to replace the pattern withpublic static java.lang.String getEntityRef(int ch)
@Deprecated
public static void escapeXML(java.lang.String source,
java.lang.StringBuffer out)
escapeXML(String, StringBuilder) instead.source - The string to escape.out - The buffer to which the results will be appended.@Deprecated
public static void escapeXMLChar(java.lang.StringBuffer target,
int ch)
escapeXMLChar(StringBuilder, int) instead.@Deprecated public static java.lang.String escapeString(java.lang.String source)
escapeXML(String) instead.public static java.lang.String escapeXML(java.lang.String source)
source - The string to escape.public static java.lang.String escapeXMLChar(int ch)
public static void escapeXML(java.lang.String source,
java.lang.StringBuilder out)
source - The string to escape.out - The buffer to which the results will be appended.public static void escapeXMLChar(java.lang.StringBuilder target,
int ch)
target - The string builder to append the escaped character intoch - The character to escapepublic static void escapeXML(java.lang.String source,
java.io.Writer out)
throws java.io.IOException
source - The string to escape.out - The Writer to which the results will be written.java.io.IOException@Deprecated public static java.lang.String escapeSpecial(java.lang.String s)
escapeJavaString(String) instead...public static java.lang.String escapeJavaString(java.lang.String s)
Example:
System.out.println(escapeJavaString("Row 1\r\nRow 2\n\tRow 3"));
Will produce the output:Row 1\r\nRow 2\n\tRow 3
as apposed to:
Row 1
Row 2
Row 3
s - The string to escape.public static java.lang.String escapeJavaStringForJSON(java.lang.String s)
s - The string to escape.public static java.lang.String trim(java.lang.String str,
char removeChar)
str - removeChar - public static java.lang.String trim(java.lang.String str)
public static java.lang.String trimLeft(java.lang.String str)
str - the string to trimpublic static java.lang.String trimRight(java.lang.String str)
str - the string to trimpublic static java.lang.String normalizeSpace(java.lang.String str)
str - the string to trimpublic static boolean matchIgnoreCase(java.lang.String string,
java.lang.String pattern)
string - the string.pattern - the pattern.public static boolean match(java.lang.String s,
java.lang.String pattern)
s - the string.pattern - the pattern.public static boolean matchAny(java.lang.String str,
java.lang.String[] patterns)
str - the string.patterns - the patterns.public static boolean matchAnyIgnoreCase(java.lang.String str,
java.lang.String[] patterns)
str - the string.patterns - the patterns.public static void sort(java.lang.String[] s)
public static void sort(java.util.List<java.lang.String> s)
public static boolean isOnlyWhitespaceOrEmpty(java.lang.String s)
public static java.lang.String[] toStringArray(java.lang.String s)
public static java.lang.String[] toStringArray(java.lang.Object[] array)
String.valueOf(Object) to convert an object to a String. If the
argument is an instance of String[] it will be returned as is.array - An object array.public static java.lang.String[] toArray(matrix.util.StringList sl)
public static java.lang.String[] toStringArray(java.util.Collection<java.lang.String> c)
public static java.lang.String[] copy(java.lang.String[] s)
s - The array to copy.public static java.lang.String cut(java.lang.String s,
int max)
If the string is cut, the following three letters are appended: ...
For example, calling this method with the args:
public static boolean contains(java.lang.String[] arr,
java.lang.String s)
arr - An array.s - public static boolean containsIgnoreCase(java.lang.String[] arr,
java.lang.String s)
arr - An array.s - public static boolean containsNull(java.lang.String[] arr)
arr - An array.public static boolean contains(java.util.Collection<java.lang.String> collection,
java.lang.String s)
collection - A collection of strings.s - The string to checkpublic static boolean contains(java.util.Iterator<java.lang.String> itr,
java.lang.String s)
itr - An iterator of stringss - The string to checkpublic static boolean containsOnly(java.util.List<java.lang.String> list,
java.lang.String s)
list - A list of stringss - The string to checkpublic static boolean containsOnly(java.util.Iterator<java.lang.String> itr,
java.lang.String s)
itr - An iterator of stringss - The string to checkpublic static java.lang.String getEOL()
public static java.lang.String[] getUniqueValues(java.lang.String[] arr)
public static matrix.util.StringList toStringList(java.lang.String... a)
a - An array of strings.public static matrix.util.StringList toStringList(java.util.Collection<java.lang.String> c)
c - A collection of strings.public static java.util.List<java.lang.String> toList(matrix.util.StringList data)
data - A enovia StringListpublic static boolean isInteger(java.lang.String s)
s - A string.public static boolean isBoolean(java.lang.String s)
s - The string to testpublic static boolean isNumber(java.lang.String s)
s - A string.public static boolean isTrue(java.lang.String s)
s - A string.public static boolean isTrue(java.lang.String s,
boolean defaultValue)
s - A string.defaultValue - The default value is returned if the supplied string
is null.public static boolean parseBoolean(java.lang.String s,
boolean defaultValue)
For any other string, the defaultValue is returned.
s - The string to be parsed into a booleandefaultValue - The default value to be returned if the s
argument is not a booleanpublic static boolean isTrueOrYes(java.lang.String s)
s - A string.public static boolean isTrueOrYes(java.lang.String s,
boolean defaultValue)
s - A string.defaultValue - The default value is returned if the supplied string
is null.public static boolean isFalseOrNo(java.lang.String s)
s - A string.public static boolean isFalseOrNo(java.lang.String s,
boolean defaultValue)
s - A string.defaultValue - The default value is returned if the supplied string
is null.public static boolean isJavaIdentifier(java.lang.String identifier)
isJavaClassName(String).identifier - The name of a Java identifier.public static java.lang.String[] splitAndEscape(java.lang.String str,
java.lang.String delim)
split(String, String) method and
escapes each entry in the array using the
escapeJavaString(String) method.str - The string to splitdelim - The delimiters to split uponpublic static java.lang.String[] subarr(java.lang.String[] arr,
int start,
int len)
public static boolean contains(java.lang.String str,
java.lang.String token,
java.lang.String delim,
boolean ignoreCase)
str - The string to check.token - The token to search for.delim - The delimiter chars that will be used to split the string
when searching for tokens.ignoreCase - Whether to ignore case when checking if a token equals
the specified token.public static boolean containsWildCard(java.lang.String s)
s - The string to checkpublic static boolean isNullOrEqualToNull(java.lang.String s)
s - A String.public static boolean isJavaClassName(java.lang.String s)
isJavaIdentifier(String).s - Possibly a java class name.public static java.util.List<java.lang.String> splitToList(java.lang.String s,
java.lang.String delimiter)
s - The string to split.delimiter - The delimiter.public static void splitToList(java.lang.String s,
java.lang.String delim,
java.util.List<java.lang.String> list)
s - The string to split.delim - The delimiter.list - The list to add the subtrings to.public static java.lang.String notNull(java.lang.String s)
s - A string.public static int indexOf(java.lang.String[] arr,
java.lang.String s)
arr - An array of string instancess - A stringpublic static java.lang.String leftpad(java.lang.String s,
int len,
char c)
s - The string to padlen - The desired length of the stringc - The character to pad withpublic static java.lang.String rightpad(java.lang.String s,
int len,
char c)
s - The string to padlen - The desired length of the stringc - The character to pad withpublic static java.lang.String nullIfEmpty(java.lang.String s)
s - The stringpublic static java.lang.String emptyIfNull(java.lang.String s)
s - The stringEMPTY_STRING if the parameter is null, otherwise the
string as provided is returned as-is.public static java.lang.String[] emptyIfNull(java.lang.String[] in)
in - The array to checkEMPTY_STRING_ARRAY if the in parameter is
null, otherwise the array as provided is returned as-ispublic static java.lang.String[] removeNulls(java.lang.String[] in)
in - The array to check.public static int parseInt(java.lang.String s,
int i)
s - The text to parsei - The default value, if unable to parse.public static long parseLong(java.lang.String s,
long defaultValue)
s - The text to parsedefaultValue - The default value, if unable to parse.public static double parseDouble(java.lang.String s,
double defaultValue)
s - The text to parse into a doubledefaultValue - The default value, if unable to parse the stringpublic static java.util.Enumeration<java.lang.String> toEnumeration(java.util.StringTokenizer st)
st - The string tokenizerpublic static java.lang.String unquote(java.lang.String str)
E.g. if the str contains:
str - public static java.lang.String toLowerCase(java.lang.String s)
s - The string to convert to lower casepublic static java.lang.String toUpperCase(java.lang.String s)
s - The string to convert to upper casepublic static java.lang.String[] reverse(java.lang.String[] arr)
arr - public static java.util.Map<java.lang.String,java.lang.String> parseArgs(java.lang.String inputString)
return StringUtils.parseArgs(s, '=', '|', false, true);
E.g. the pipe character '|' is used to separate multiple key/value pairs and the '=' is used to separate the key from its value.
inputString - The string to parse into an argument mapparseArgs(String, char, boolean),
parseArgs(String, char, char, boolean, boolean)public static java.util.Map<java.lang.String,java.lang.String> parseArgs(java.lang.String inputString,
char argSeparator,
boolean caseInsensitiveKeys)
public static java.util.Map<java.lang.String,java.lang.String> parseArgs(java.lang.String inputString,
char valueSeparator,
char argSeparator,
boolean caseInsensitiveKeys,
boolean escapeBackslashes)
inputString ::= <arg>[<argSeparator><arg>]
arg ::= <name><valueSeparator>;<value>
name ::= string
value ::= string
NOTE: The backslash character '\' is used for escaping if the argument escapeBackslashes is true.
E.g. if the arg name contains a '\' or the valueSeparator character, these needs to be escaped. Also, if the arg value contains a '\' or 'the argSeparator char, these also needs to be escaped.
The table below illustrates some examples and what return value is exepected (the separator char is '|' in this case and the value separator is '='):
| Input String | Parsed Map | ||||||
|---|---|---|---|---|---|---|---|
| test=value1|foo=bar|tvc=great |
|
||||||
| t\\e\=st=val\|\\\|ue1|f\\o\\o=b\|a\|r|tvc=great |
|
inputString - The string to parse into an argument mapvalueSeparator - The separator used to separate a key/value pair.argSeparator - The character used to separate multiple arguments.caseInsensitiveKeys - True to construct a map that allows querying
the map in a case insensitive way.escapeBackslashes - True to support escaping using the backslash
characterpublic static java.util.Map<java.lang.String,java.lang.String> asPropertyMap(java.lang.String s)
load method.s - The string to loadpublic static java.util.Map<java.lang.String,java.lang.String> asPropertyMap(java.lang.String s,
java.util.Map<java.lang.String,java.lang.String> target)
load method.s - The string to loadtarget - The target map. If null, a new HashMap is created.public static boolean isBlank(java.lang.String s)
isOnlyWhitespaceOrEmpty(String)s - The string to testpublic static boolean isNotBlank(java.lang.String s)
s - The string to test.public static java.lang.String trimToNull(java.lang.String s)
s - The string to be trimmedpublic static java.lang.String trimToEmpty(java.lang.String s)
s - The string to be trimmedpublic static java.lang.String capitalize(java.lang.String s)
s - The string to be capitalized.public static boolean equals(java.lang.String left,
java.lang.String right)
left - The string to be compared for equality.right - The string to be compared for equality.public static boolean equalsIgnoreCase(java.lang.String left,
java.lang.String right)
left - The string to be compared for equality.right - The string to be compared for equality.public static boolean contains(java.lang.String source,
java.lang.String search)
source - The string.search - The string.public static boolean contains(java.lang.String source,
java.lang.String search,
boolean caseSensitive)
source - The stringsearch - The stringcaseSensitive - booleanpublic static boolean containsIgnoreCase(java.lang.String source,
java.lang.String search)
source - The stringsearch - The stringpublic static boolean startsWith(java.lang.String source,
java.lang.String prefix)
source - The stringprefix - The stringpublic static boolean startsWith(java.lang.String source,
java.lang.String prefix,
boolean caseSensitive)
source - The stringprefix - The stringcaseSensitive - booleanpublic static boolean startsWithIgnoreCase(java.lang.String source,
java.lang.String prefix)
source - The stringprefix - The stringpublic static java.lang.String toString(java.lang.String value,
java.lang.String fallback)
value - The stringfallback - The stringpublic static java.lang.String defaultIfEmpty(java.lang.String value,
java.lang.String fallback)
value - The stringfallback - The stringpublic static java.lang.String next(java.util.Iterator<java.lang.String> itr,
java.lang.String fallback)
itr - The string Iteratorfallback - The stringpublic static java.lang.String next(java.util.Iterator<java.lang.String> itr)
itr - The string Iteratorpublic static java.lang.String stripNonValidXMLCharacters(java.lang.String source)
source - The String whose non-valid characters we want to remove.public static java.lang.String removeAllWhitespaces(java.lang.String s)
For example, a string containing following text: (the whitespace is marked).
A TEXT WITH SOME SPACES . ^ ^^^^^^^^^ ^^^^ ^ ^^^Will after calling this method be:
s - An input stringpublic static java.lang.String addWhitespaceBetweenCharacters(java.lang.String s)
For example, a string containing following text: (the whitespace is marked).
HELLO WOR LD!
^ ^^^
Will after calling this method be:
s - An input stringpublic static java.util.Collection<java.lang.String> removeBlanks(java.util.Collection<java.lang.String> input)
input - The Collectionpublic static boolean isEmpty(java.lang.String[] values)
values - array of stringpublic static java.lang.String toEnumConstant(java.lang.String name)
name - enum namepublic static java.lang.String toEnumLower(java.lang.String name)
name - enum namepublic static int compareTo(java.lang.String left,
java.lang.String right)
left - string to compareright - string to comparepublic static int compareTo(java.lang.String left,
java.lang.String right,
boolean ignoreCase)
left - string to compareright - string to compareignoreCase - whether to ignore case while comparingpublic static java.lang.String joinListValues(java.util.List<java.lang.String> items,
java.lang.String sep)
items - List to Joinsep - string contains the separator by which it will join the listpublic static java.lang.String escapeScriptTags(java.lang.String str)
str - public static java.lang.String escapeJavascript(java.lang.String str)
str - Copyright ? Technia AB. All Rights Reserved.