public final class Strings extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Strings.CharacterFilter |
static class |
Strings.Range
Represents a range between two integers.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
EMPTY
An empty string constant
|
| Constructor and Description |
|---|
Strings() |
| Modifier and Type | Method and Description |
|---|---|
static String |
capitalize(String string)
Capitalize the first character of the given string.
|
static boolean |
compare(String me,
String you)
Compare two strings.
|
static int |
count(String string,
char c)
Count the number of instances of character within a string.
|
static int |
count(String string,
String substring)
Count the number of instances of substring within a string.
|
static String |
defaultToString(Object object)
The default toString implementation of an object
|
static void |
defaultToString(StringBuffer buffer,
Object object)
The default toString implementation of an object
|
static void |
defaultToString(StringBuilder buffer,
Object object)
The default toString implementation of an object
|
static boolean |
hasLength(String string)
Check that the given string param is neither null nor of length 0.
|
static boolean |
isEjbQlIdentifier(String s)
Check whether the given String is an identifier according to the EJB-QL definition.
|
static boolean |
isEmpty(String string)
Check if the given string is empty.
|
static boolean |
isJavaKeyword(String s)
Check whether the given String is a reserved Java Keyword according to the Java Language Specifications.
|
static boolean |
isNullOrEmpty(String string)
Check if the given string is null or empty.
|
static boolean |
isValidJavaIdentifier(String s)
Check whether the given String is a valid identifier according to the Java Language specifications.
|
static String |
join(byte[] array)
Convert and join an array of bytes into one string.
|
static String |
join(Object[] array)
Convert and join an array of objects into one string.
|
static String |
join(Object[] array,
String delim)
Join an array of strings into one delimited string.
|
static String |
join(Object[] array,
String prefix,
String separator,
String suffix)
Return a string composed of the given array.
|
static String |
join(StringBuffer buff,
Object[] array,
String delim)
Join an array of strings into one delimited string.
|
static String |
join(StringBuffer buff,
Object[] array,
String prefix,
String separator,
String suffix)
Return a string composed of the given array.
|
static int |
nthIndexOf(String string,
String token,
int index)
Return the nth index of the given token occurring in the given string.
|
static String |
pad(Object obj,
int count)
Return a string padded with the given string value of an object for the given count.
|
static String |
pad(StringBuffer buff,
String string,
int count)
Return a string padded with the given string for the given count.
|
static String |
pad(String string,
int count)
Return a string padded with the given string for the given count.
|
static Locale |
parseLocaleString(String localeString)
Parse the given localeString into a
Locale. |
static long |
parsePositiveTimePeriod(String period)
Same like parseTimePeriod(), but guards for negative entries.
|
static long |
parseTimePeriod(String period)
Parses a time period into a long.
|
static Strings.Range |
rangeOf(String beginToken,
String endToken,
String string)
Return the range from a begining token to an ending token.
|
static Strings.Range |
rangeOf(String beginToken,
String endToken,
String string,
int fromIndex)
Return the range from a begining token to an ending token.
|
static String |
removeWhiteSpace(String s)
Returns a new string with all the whitespace removed
|
static String[] |
split(String string,
String delim)
Split up a string into multiple strings based on a delimiter.
|
static String[] |
split(String string,
String delim,
int limit)
Split up a string into multiple strings based on a delimiter.
|
static String |
subst(StringBuffer buff,
String string,
Map<?,?> map,
String beginToken,
String endToken)
Substitute sub-strings in side of a string.
|
static String |
subst(StringBuffer buff,
String string,
String[] replace,
char token)
Substitute index identifiers with the replacement value from the given array for the corresponding index.
|
static String |
subst(StringBuffer buff,
String from,
String to,
String string)
Substitute sub-strings in side of a string.
|
static String |
subst(String string,
Map<?,?> map,
String beginToken,
String endToken)
Substitute sub-strings in side of a string.
|
static String |
subst(String string,
String[] replace)
Substitute index identifiers (with
% for the index token) with the replacement value from the given
array for the corresponding index. |
static String |
subst(String string,
String[] replace,
char token)
Substitute index identifiers with the replacement value from the given array for the corresponding index.
|
static String |
subst(String from,
String to,
String string)
Substitute sub-strings in side of a string.
|
static String[] |
tokenizeToStringArray(String str,
String delimiters,
boolean trimTokens,
boolean ignoreEmptyTokens)
Tokenize the given String into a String array via a StringTokenizer.
|
static URI |
toURI(String urispec) |
static URI |
toURI(String urispec,
String relativePrefix) |
static URL |
toURL(String urlspec)
Make a URL from the given string.
|
static URL |
toURL(String urlspec,
String relativePrefix)
Make a URL from the given string.
|
static String[] |
trim(String[] strings)
Trim each string in the given string array.
|
static String |
trimLeadingCharacter(String str,
char leadingCharacter)
Trim all occurences of the supplied leading character from the given String.
|
static String |
trimLeadingCharacter(String str,
Strings.CharacterFilter checker)
Trim all occurences of the supplied leading character from the given String.
|
static String |
trimLeadingWhitespace(String str)
Trim leading whitespace from the given String.
|
public static final String EMPTY
public static String subst(StringBuffer buff, String from, String to, String string)
buff - Stirng buffer to use for substitution (buffer is not reset)from - String to substitute fromto - String to substitute tostring - String to look for from inpublic static String subst(String from, String to, String string)
from - String to substitute fromto - String to substitute tostring - String to look for from inpublic static String subst(StringBuffer buff, String string, Map<?,?> map, String beginToken, String endToken)
buff - String buffer to use for substitution (buffer is not reset)string - String to subst mappings inmap - Map of from->to stringsbeginToken - Beginning tokenendToken - Ending tokenpublic static String subst(String string, Map<?,?> map, String beginToken, String endToken)
string - String to subst mappings inmap - Map of from->to stringsbeginToken - Beginning tokenendToken - Ending tokenpublic static String subst(StringBuffer buff, String string, String[] replace, char token)
buff - The string buffer used for the substitution (buffer is not reset).string - String substitution format.replace - Array of strings whose values will be used as replacements in the given string when a token with
their index is found.token - The character token to specify the start of an index reference.public static String subst(String string, String[] replace, char token)
string - String substitution format.replace - Array of strings whose values will be used as replacements in the given string when a token with
their index is found.token - The character token to specify the start of an index reference.public static String subst(String string, String[] replace)
% for the index token) with the replacement value from the given
array for the corresponding index.string - String substitution format.replace - Array of strings whose values will be used as replacements in the given string when a token with
their index is found.public static Strings.Range rangeOf(String beginToken, String endToken, String string, int fromIndex)
beginToken - String to indicate begining of range.endToken - String to indicate ending of range.string - String to look for range in.fromIndex - Beginning index.public static Strings.Range rangeOf(String beginToken, String endToken, String string)
beginToken - String to indicate begining of range.endToken - String to indicate ending of range.string - String to look for range in.public static String[] split(String string, String delim, int limit)
string - String to split up.delim - Delimiter.limit - Limit the number of strings to split into (-1 for no limit).public static String[] split(String string, String delim)
string - String to split up.delim - Delimiter.public static String join(StringBuffer buff, Object[] array, String delim)
buff - String buffered used for join (buffer is not reset).array - Array of objects to join as strings.delim - Delimiter to join strings with or null.public static String join(Object[] array, String delim)
array - Array of objects to join as strings.delim - Delimiter to join strings with or null.public static String join(Object[] array)
array - Array of objects to join as strings.public static String join(byte[] array)
array - Array of objects to join as strings.public static String join(StringBuffer buff, Object[] array, String prefix, String separator, String suffix)
buff - Buffer used to construct string value (not reset).array - Array of objects.prefix - String prefix.separator - Element sepearator.suffix - String suffix.public static String join(Object[] array, String prefix, String separator, String suffix)
array - Array of objects.prefix - String prefix.separator - Element sepearator.suffix - String suffix.public static int count(String string, String substring)
string - String to look for substring in.substring - Sub-string to look for.public static int count(String string, char c)
string - String to look for substring in.c - Character to look for.public static String pad(StringBuffer buff, String string, int count)
buff - String buffer used for padding (buffer is not reset).string - Pad element.count - Pad count.public static String pad(String string, int count)
string - Pad element.count - Pad count.public static String pad(Object obj, int count)
obj - Object to convert to a string.count - Pad count.public static boolean compare(String me, String you)
Compare two strings.
Both or one of them may be null.
me - you - public static boolean isEmpty(String string)
string - String to checkpublic static boolean isNullOrEmpty(String string)
string - String to checkpublic static int nthIndexOf(String string, String token, int index)
string - String to search.token - Token to match.index - Nth index.public static String capitalize(String string)
string - String to capitalize.IllegalArgumentException - String is public static String[] trim(String[] strings)
This modifies the string array.
strings - String array to trim.public static URL toURL(String urlspec, String relativePrefix) throws MalformedURLException
If the string is a properly formatted file URL, then the file portion will be made canonical.
If the string is an invalid URL then it will be converted into a file URL.
urlspec - The string to construct a URL for.relativePrefix - The string to prepend to relative file systemPaths, or null to disable prepending.MalformedURLException - Could not make a URL for the given string.public static URI toURI(String urispec, String relativePrefix) throws URISyntaxException
URISyntaxExceptionpublic static URL toURL(String urlspec) throws MalformedURLException
urlspec - The string to construct a URL for.MalformedURLException - Could not make a URL for the given string.toURL(String,String)public static URI toURI(String urispec) throws URISyntaxException
urispec - URISyntaxException - for any errorpublic static final boolean isJavaKeyword(String s)
s - String to checktrue if the given String is a reserved Java keyword, false otherwise.public static final boolean isEjbQlIdentifier(String s)
s - String to checktrue if the given String is a reserved identifier in EJB-QL, false otherwise.public static final boolean isValidJavaIdentifier(String s)
s - String to checktrue if the given String is a valid Java identifier, false otherwise.public static String removeWhiteSpace(String s)
s - the source stringpublic static final String defaultToString(Object object)
object - the objectpublic static final void defaultToString(StringBuilder buffer, Object object)
object - the objectbuffer - the string builderpublic static final void defaultToString(StringBuffer buffer, Object object)
object - the objectbuffer - the string bufferpublic static long parseTimePeriod(String period)
period - the stringfied time periodNumberFormatExceptionpublic static long parsePositiveTimePeriod(String period)
period - the stringfied time periodNumberFormatExceptionpublic static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
str - the String to tokenizedelimiters - the delimiter characters, assembled as String (each of those characters is individually
considered as delimiter)trimTokens - trim the tokens via String's trimignoreEmptyTokens - omit empty tokens from the result array (only applies to tokens that are empty after
trimming; StringTokenizer will not consider subsequent delimiters as token in the first place).public static String trimLeadingWhitespace(String str)
str - the string to checkCharacter.isWhitespace(char)public static String trimLeadingCharacter(String str, char leadingCharacter)
str - the string to checkleadingCharacter - the leading character to be trimmedpublic static String trimLeadingCharacter(String str, Strings.CharacterFilter checker)
str - the string to checkchecker - the character checkerpublic static boolean hasLength(String string)
string - the stringpublic static Locale parseLocaleString(String localeString)
Locale.
This is the inverse operation of Locale's toString.localeString - the locale stringCopyright © 2014 JBoss by Red Hat. All rights reserved.