public class StrUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
arraysEqual(Object[] array1,
Object[] array2)
Compare 2 array
|
static String |
arrayToString(Object[] array)
Change a Object array to "obj1,obj2...,objn" String
|
static String |
arrayToString(Object[] array,
String seperateString)
Change a Object array to connected string by given seperateString
|
static boolean |
containsIgnoreCase(String str,
String searchStr)
Find if exist searchStr in str ignore case
|
static boolean |
containsWhitespace(CharSequence str)
Check whether the given CharSequence contains any whitespace characters.
|
static boolean |
containsWhitespace(String str)
Check whether the given String contains any whitespace characters.
|
static int |
countMatches(CharSequence str,
char ch)
Counts how many times the char appears in the given string.
|
static String |
getRandomString(int length) |
static boolean |
hasLength(CharSequence str)
Check that the given CharSequence is neither
null nor of length
0. |
static boolean |
hasLength(String str)
Check that the given String is neither
null nor of length 0. |
static int |
indexOfIgnoreCase(String str,
String searchStr)
Return first postion ignore case, return -1 if not found
|
static boolean |
isEmpty(Object str)
Check whether the given String is empty.
|
static String[] |
joinStringArray(String[] array1,
String[] array2)
Join 2 String array into one
|
static int |
lastIndexOfIgnoreCase(String str,
String searchStr)
Return last sub-String position ignore case, return -1 if not found
|
static String |
listToString(List<?> lst)
Change a Object List to "obj1,obj2...,objn" String
|
static String |
replace(String originString,
String oldPattern,
String newPattern)
Replace all occurrences of a substring within a string with another
string.
|
static String |
replaceIgnoreCase(String str,
String findtxt,
String replacetxt)
Replace all sub strings ignore case
replaceIgnoreCase("AbcDECd", "Cd", "FF") = "AbFFEFF" |
static boolean |
startsWithIgnoreCase(String str,
String prefix)
Test if the given String starts with the specified prefix, ignoring
upper/lower case.
|
static String |
substringBetween(String str,
String open,
String close)
Gets the String that is nested in between two Strings.
|
static List<String> |
substringsBetween(String txt,
String tag)
Return all sub-Strings between 1 tags
|
static String |
trimAllWhitespace(String str)
Trim all whitespace from the given String: leading, trailing, and
in between characters.
|
static String |
trimLeadingCharacter(String str,
char leadingCharacter)
Trim all occurrences of the supplied leading character from the given
String.
|
static String |
trimLeadingWhitespace(String str)
Trim leading whitespace from the given String.
|
static String |
trimTrailingCharacter(String str,
char trailingCharacter)
Trim all occurrences of the supplied trailing character from the given
String.
|
static String |
trimTrailingWhitespace(String str)
Trim trailing whitespace from the given String.
|
static String |
trimWhitespace(String str)
Trim leading and trailing whitespace from the given String.
|
public static boolean isEmpty(Object str)
public static boolean hasLength(CharSequence str)
null nor of length
0. Note: Will return true for a CharSequence that purely consists
of whitespace.
StrUtils.hasLength(null) = false
StrUtils.hasLength("") = false
StrUtils.hasLength(" ") = true
StrUtils.hasLength("Hello") = true
str - the CharSequence to check (may be null)true if the CharSequence is not null and has length#hasText(String)public static boolean hasLength(String str)
null nor of length 0.
Note: Will return true for a String that purely consists of
whitespace.str - the String to check (may be null)true if the String is not null and has lengthhasLength(CharSequence)public static boolean containsWhitespace(CharSequence str)
str - the CharSequence to check (may be null)true if the CharSequence is not empty and contains at
least 1 whitespace characterCharacter.isWhitespace(char)public static boolean containsWhitespace(String str)
str - the String to check (may be null)true if the String is not empty and contains at least 1
whitespace charactercontainsWhitespace(CharSequence)public static String trimWhitespace(String str)
str - the String to checkCharacter.isWhitespace(char)public static String trimAllWhitespace(String str)
str - the String to checkCharacter.isWhitespace(char)public static String trimLeadingWhitespace(String str)
str - the String to checkCharacter.isWhitespace(char)public static String trimTrailingWhitespace(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 trimTrailingCharacter(String str, char trailingCharacter)
str - the String to checktrailingCharacter - the trailing character to be trimmedpublic static boolean startsWithIgnoreCase(String str, String prefix)
str - the String to checkprefix - the prefix to look forString.startsWith(java.lang.String, int)public static boolean containsIgnoreCase(String str, String searchStr)
public static String replace(String originString, String oldPattern, String newPattern)
originString - The original StringoldPattern - old String Pattern to replacenewPattern - new String pattern to insertpublic static String replaceIgnoreCase(String str, String findtxt, String replacetxt)
public static int indexOfIgnoreCase(String str, String searchStr)
public static int lastIndexOfIgnoreCase(String str, String searchStr)
public static List<String> substringsBetween(String txt, String tag)
public static String substringBetween(String str, String open, String close)
null input String returns null. A
null open/close returns null (no match). An
empty ("") open and close returns an empty string.
StringUtils.substringBetween("wx[b]yz", "[", "]") = "b"
StringUtils.substringBetween(null, *, *) = null
StringUtils.substringBetween(*, null, *) = null
StringUtils.substringBetween(*, *, null) = null
StringUtils.substringBetween("", "", "") = ""
StringUtils.substringBetween("", "", "]") = null
StringUtils.substringBetween("", "[", "]") = null
StringUtils.substringBetween("yabcz", "", "") = ""
StringUtils.substringBetween("yabcz", "y", "z") = "abc"
StringUtils.substringBetween("yabczyabcz", "y", "z") = "abc"
str - the String containing the substring, may be nullopen - the String before the substring, may be nullclose - the String after the substring, may be nullnull if no matchpublic static int countMatches(CharSequence str, char ch)
Counts how many times the char appears in the given string.
A null or empty ("") String input returns 0.
StringUtils.countMatches(null, *) = 0
StringUtils.countMatches("", *) = 0
StringUtils.countMatches("abba", 0) = 0
StringUtils.countMatches("abba", 'a') = 2
StringUtils.countMatches("abba", 'b') = 2
StringUtils.countMatches("abba", 'x') = 0
str - the CharSequence to check, may be nullch - the char to countnullpublic static String getRandomString(int length)
public static boolean arraysEqual(Object[] array1, Object[] array2)
public static String arrayToString(Object[] array)
public static String arrayToString(Object[] array, String seperateString)
public static String listToString(List<?> lst)
Copyright © 2017. All rights reserved.