public class StringHelper extends Object
| 构造器和说明 |
|---|
StringHelper() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
capitalFirstLetter(String str)
Capital first letter string.
|
static boolean |
changeString2boolean(String string)
Change string 2 boolean boolean.
|
static String[] |
concatenateStringArrays(String[] array1,
String[] array2)
Concatenate the given String arrays into one, with overlapping array
elements included twice.
|
static boolean |
containsAny(String str,
char[] searchChars)
Checks if the String contains any character in the given set of
characters.
|
static int |
countOccurrencesOf(String str,
String sub)
Count the occurrences of the substring in string s.
|
static boolean |
endsWithIgnoreCase(String str,
String suffix)
Check a String ends with another string ignoring the case.
|
static String |
escape(boolean shouldEscape,
String src)
Escapes the characters in a
String using XML entities only if the
passed boolean is true. |
static String |
escape(String src)
Escapes the characters in a
String using XML entities. |
static String |
extractNumber(String str)
Extract number string.
|
static List<String> |
find(String target,
String patten)
Find list.
|
static String |
getBetweenString(String origiString,
String beforeStr,
String afterStr)
Gets between string.
|
static int |
getRandomInt(int min,
int max)
get a random Integer with the range [min, max)
|
static int[] |
getRandomIntWithoutDuplicate(int min,
int max,
int size)
get a integer array filled with random integer without duplicate [min,
max)
|
static String[] |
getTokensArray(String str,
String delimeter)
This method is used to split the given string into different tokens at
the occurrence of specified delimiter
|
static List<String> |
getTokensList(String str,
String delimeter)
This method is used to split the given string into different tokens at
the occurrence of specified delimiter
|
static boolean |
isDouble(String str)
Check whether the string is double format or not
|
static boolean |
isEmail(String str)
Check whether the string is email format or not
|
static boolean |
isEmpty(String str)
判断字符串是否为空
|
static boolean |
isInteger(String str)
Check whether the string is Integer format or not
|
static boolean |
isLetter(String str)
Check if the string is letter or not
|
static boolean |
isNotEmpty(String str)
判断字符串是否非空
|
static boolean |
isNumber(String str)
Check if the string is a number or not
|
static String |
join(Iterable<?> target,
String separator)
Join string.
|
static String |
join(Object[] target,
String separator)
Join string.
|
static String[] |
mergeStringArrays(String[] array1,
String[] array2)
This method can be used to merge 2 arrays of string values.
|
static String |
removeSpecialChar(String str)
Remove special char string.
|
static boolean |
startsWithIgnoreCase(String str,
String prefix)
Check a String starts with another string ignoring the case.
|
static String |
trimAllWhitespace(String str)
Trim all whitespace from the given String: leading, trailing, and
inbetween characters.
|
static String[] |
trimArray(String[] values)
This method can be used to trim all the String values in the string
array.
|
static List<String> |
trimList(List<String> values)
This method can be used to trim all the String values in the string list.
|
static String |
uncapitalFirstLetter(String str)
Uncapitalizes a String changing the first letter to title case as per
Character.toLowerCase(char). |
static String |
unquote(String str)
This String util method removes single or double quotes from a string if
its quoted. for input string = "mystr1" output will be = mystr1 for input
string = 'mystr2' output will be = mystr2
|
static String |
urlDecode(String str)
Url decode string.
|
static String |
urlEncode(String str)
Url encode string. url转码
|
public static boolean isEmpty(String str)
str - the strpublic static boolean isNotEmpty(String str)
str - the strpublic static boolean isInteger(String str)
str - the strpublic static boolean isDouble(String str)
str - the strpublic static boolean isEmail(String str)
str - the strpublic static boolean isNumber(String str)
str - String to be checkedpublic static boolean isLetter(String str)
str - String to be checkedpublic static String extractNumber(String str)
str - the strpublic static String urlEncode(String str)
str - the strpublic static String urlDecode(String str)
str - the strpublic static boolean changeString2boolean(String string)
string - the stringpublic static int countOccurrencesOf(String str, String sub)
str - string to search in. Return 0 if this is null.sub - string to search for. Return 0 if this is null.public static String unquote(String str)
str - String value to be unquoted.public static boolean endsWithIgnoreCase(String str, String suffix)
str - the strsuffix - the suffixpublic static boolean startsWithIgnoreCase(String str, String prefix)
str - the strprefix - the prefixpublic static boolean containsAny(String str, char[] searchChars)
null String will return false. A
null or zero length search array will return
false.
StringHelper.containsAny(null, *) = false
StringHelper.containsAny("", *) = false
StringHelper.containsAny(*, null) = false
StringHelper.containsAny(*, []) = false
StringHelper.containsAny("zzabyycdxx",['z','a']) = true
StringHelper.containsAny("zzabyycdxx",['b','y']) = true
StringHelper.containsAny("aba", ['z']) = falsestr - the String to check, may be nullsearchChars - the chars to search for, may be nulltrue if any of the chars are found, false if no match or null inputpublic static String trimAllWhitespace(String str)
str - the String to checkjava.lang.Character#isWhitespacejava.lang.Character#isWhitespacejava.lang.Character#isWhitespacejava.lang.Character#isWhitespacepublic static String removeSpecialChar(String str) throws PatternSyntaxException
str - the strPatternSyntaxException - the pattern syntax exceptionpublic static String capitalFirstLetter(String str)
str - the strpublic static String uncapitalFirstLetter(String str)
Character.toLowerCase(char). No other letters are changed.
StringHelper.uncapitalFirstLetter(null) = null
StringHelper.uncapitalFirstLetter("") = ""
StringHelper.uncapitalFirstLetter("Cat") = "cat"
StringHelper.uncapitalFirstLetter("CAT") = "cAT"str - the String to uncapitalFirstLetter, may be nullnull if null String input#capitalFirstLetter(String)#capitalFirstLetter(String)#capitalFirstLetter(String)#capitalFirstLetter(String)public static String join(Object[] target, String separator)
target - the targetseparator - the separatorpublic static String join(Iterable<?> target, String separator)
target - the targetseparator - the separatorpublic static String[] getTokensArray(String str, String delimeter)
str - The string that needs to be brokendelimeter - The delimiter used to break the stringpublic static List<String> getTokensList(String str, String delimeter)
str - The string that needs to be brokendelimeter - The delimiter used to break the stringpublic static String getBetweenString(String origiString, String beforeStr, String afterStr)
origiString - the origi stringbeforeStr - the before strafterStr - the after strpublic static String[] trimArray(String[] values)
values - the valuespublic static List<String> trimList(List<String> values)
values - the valuespublic static String[] mergeStringArrays(String[] array1, String[] array2)
array1 - the array 1array2 - the array 2public static String[] concatenateStringArrays(String[] array1, String[] array2)
array1 - the first array (can be null)array2 - the second array (can be null)null if both given arrays were null)public static int[] getRandomIntWithoutDuplicate(int min,
int max,
int size)
min - the minimum valuemax - the maximum valuesize - the capacity of the arraypublic static int getRandomInt(int min,
int max)
min - the minimum valuemax - the maximum valuepublic static String escape(String src)
String using XML entities.src - the String to escape, may be nullString, null if null string inputpublic static String escape(boolean shouldEscape, String src)
String using XML entities only if the
passed boolean is true.shouldEscape - the should escapesrc - the String to escape.String if shouldEscape is set to true, an unchanged String otherwise.Copyright © 2017. All rights reserved.