public final class StringUtils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
concat(Iterable<?> inputs,
String prefix,
String separator,
String suffix)
Splits the provided String into a List.
|
static String |
emptyIfNull(Object aString)
Checks if aString is null and if so, returns Empty String.
|
static String |
escapeXml(String str)
Escapes special characters in a
String . |
static String |
getMD5(String input)
Computes MD5 checksum for the provided String.
|
static boolean |
isEmpty(String aString)
This method checks if the parameter is null or only contains blank characters.
|
static boolean |
isIn(char cc,
char[] ends)
Is "cc" character present in "ends" array ?
|
static int |
lastIndexOf(String s,
char c,
int minIndex)
Searches the last index of a character in a String, searching
backwards from last char until min index.
|
static String |
ltrim(String aString) |
static String |
nullIfEmpty(String aString)
This method return null if the parameter aString is null or only contains blank characters otherwise aString is
returned
|
static String |
rtrim(String aString) |
static List<String> |
stringToListBySeparator(String input,
String separator)
Splits the provided String into a List.
|
static Set<String> |
stringToSetBySeparator(String input,
String separator)
Splits the provided String into an ordered Set.
|
static String |
trim(String aString)
This method checks if the parameter is null and if not suppresses blank characters
at left and right sides.
|
static String |
unescapeJava(String str)
Unescapes any Java literals found in the
String . |
static void |
unescapeJava(Writer out,
String str)
Unescapes any Java literals found in the
String to a
Writer . |
public static int lastIndexOf(String s, char c, int minIndex)
String.lastIndexOf(int, int)
as it searches the right part of the offset instead of the left part.public static String trim(String aString)
aString
- String to trimpublic static boolean isEmpty(String aString)
aString
- String to testpublic static String nullIfEmpty(String aString)
aString
- String to testpublic static String emptyIfNull(Object aString)
aString
- String to checkpublic static Set<String> stringToSetBySeparator(String input, String separator)
public static List<String> stringToListBySeparator(String input, String separator)
public static String concat(Iterable<?> inputs, String prefix, String separator, String suffix)
public static String getMD5(String input)
input
- String to compute checksum ontoNullPointerException
- if input is nullpublic static String escapeXml(String str)
String
.str
- The String
to escape.String
.public static String unescapeJava(String str)
Unescapes any Java literals found in the String
.
For example, it will turn a sequence of '\'
and
'n'
into a newline character, unless the '\'
is preceded by another '\'
.
str
- the String
to unescape, may be nullString
, null
if null string inputpublic static void unescapeJava(Writer out, String str) throws IOException
Unescapes any Java literals found in the String
to a
Writer
.
For example, it will turn a sequence of '\'
and
'n'
into a newline character, unless the '\'
is preceded by another '\'
.
Illegal escapes result in an exception. For example, "\d" will fail.
A null
string input has no effect.
out
- the Writer
used to output unescaped charactersstr
- the String
to unescape, may be nullIllegalArgumentException
- if the Writer is null
IOException
- if error occurs on underlying Writerpublic static boolean isIn(char cc, char[] ends)