public class StringUtils extends Object
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
areStringsEqual(String str1,
String str2)
Utility to tell if two strings are the same.
|
static String |
booleanArrayToString(boolean[] ba)
Utility to convert a boolean[] to a String.
|
static String |
collectionToString(Collection coll)
Converts the given collection of objects to string as a comma-separated
list.
|
static Set<String> |
convertCommaSeparatedStringToSet(String str)
Converts the input comma-separated string into a Set of the individual strings, with each string trimmed and converted to UPPERCASE.
|
static String |
exponentialFormatBigDecimal(BigDecimal bd)
Formats the given BigDecimal value into a floating-point literal (like we find in SQL).
|
static String |
getDecodedStringFromURLString(String urlString)
Convenience method to decode a URL string for use (so spaces are allowed)
|
static String |
getEncodedURLStringFromString(String string)
Convenience method to encode a URL string for use (so spaces are allowed)
|
static File |
getFileForFilename(String filename)
Convenience method to get a File for the specified filename.
|
static JarFile |
getJarFileForFilename(String filename)
Convenience method to get a JarFile for the specified filename.
|
static String |
getMessageFromRootCauseOfThrowable(Throwable thr)
Convenience method to take a throwable and navigate up to the root cause and return the message of the root cause.
|
static String |
getNameOfClass(Class cls) |
static String |
getStringFromException(Throwable exception)
Gets a String message from an Exception.
|
static String |
getStringFromStackTrace(Throwable ex)
Convert an exception to a String with full stack trace
|
static String |
intArrayToString(int[] ia)
Utility to convert an int[] to a String.
|
static boolean |
isEmpty(String s)
check string is null or length is 0.
|
static boolean |
isWhitespace(String str)
Utility to check if a string is whitespace.
|
static String |
leftAlignedPaddedString(String input,
int length)
Utility to return a left-aligned version of a string padded to the
number of characters specified.
|
static String |
mapToString(Map map)
Converts the given map of objects to string as a comma-separated list.
|
static boolean |
notEmpty(String s)
check string is not null and length > 0.
|
static String |
objectArrayToString(Object[] arr)
Utility to convert an Object[] to a String.
|
static String |
removeSpecialTagsFromString(String str)
Method to return the input string with all special tags (end-of-line, tab, etc) replaced
by spaces.
|
static String |
replaceAll(String theString,
String toReplace,
String replacement)
A more efficient version than
String.replace(CharSequence, CharSequence) which uses
Regex for the implementation and requires compilation for every execution. |
static String |
rightAlignedPaddedString(String input,
int length)
Utility to return a right-aligned version of a string padded to the
number of characters specified.
|
static String[] |
split(String valuesString,
String token)
Splits a list of values separated by a token
|
static String |
toJVMIDString(Object obj)
Utility to convert an object to a JVM type string.
|
public static String getMessageFromRootCauseOfThrowable(Throwable thr)
thr
- The Throwablepublic static String getStringFromStackTrace(Throwable ex)
ex
- the exceptionpublic static File getFileForFilename(String filename)
filename
- Name of filepublic static JarFile getJarFileForFilename(String filename) throws IOException
filename
- Name of fileIOException
- if there is a problem opening the JarFilepublic static String getDecodedStringFromURLString(String urlString)
urlString
- The URL stringpublic static String getEncodedURLStringFromString(String string)
string
- The stringpublic static String replaceAll(String theString, String toReplace, String replacement)
String.replace(CharSequence, CharSequence)
which uses
Regex for the implementation and requires compilation for every execution.theString
- The string to usetoReplace
- The string to replace.replacement
- The replacement string.public static boolean isWhitespace(String str)
str
- The string to checkpublic static boolean areStringsEqual(String str1, String str2)
str1
- The first stringstr2
- The second stringpublic static String leftAlignedPaddedString(String input, int length)
input
- The input stringlength
- The length desiredpublic static String rightAlignedPaddedString(String input, int length)
input
- The input stringlength
- The length desiredpublic static String[] split(String valuesString, String token)
valuesString
- the text to be splitedtoken
- the tokenpublic static Set<String> convertCommaSeparatedStringToSet(String str)
str
- The input stringpublic static String toJVMIDString(Object obj)
obj
- The objectpublic static String booleanArrayToString(boolean[] ba)
ba
- The boolean[]public static String intArrayToString(int[] ia)
ia
- The int[]public static String objectArrayToString(Object[] arr)
arr
- The Object[]public static String collectionToString(Collection coll)
coll
- collection of objects to be convertedpublic static String mapToString(Map map)
map
- Map to be convertedpublic static boolean isEmpty(String s)
s
- check stringpublic static boolean notEmpty(String s)
s
- check stringpublic static String exponentialFormatBigDecimal(BigDecimal bd)
bd
- The number to format.public static String removeSpecialTagsFromString(String str)
str
- The stringpublic static String getStringFromException(Throwable exception)
exception
- to be read and transformed into a message to printCopyright © 2019. All rights reserved.