public class StringUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
INDEX_OF_NOT_FOUND |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
containsIgnoreCase(String source,
String target)
Returns true if given string contains given target string ignore case,
false otherwise.
|
static boolean |
containsWhitespace(String source)
Returns true if given string have white span, false otherwise.
|
static boolean |
containsWord(String text,
String word)
Returns true if given text contains given word; false otherwise.
|
static boolean |
containsWordIgnoreCase(String text,
String word)
Returns true if given text contains given word ignore case; false
otherwise.
|
static int |
count(String source,
String target)
Count how much target in souce string.统计target在source中出现的次数。
|
static int |
countIgnoreCase(String source,
String target)
Count how much target in souce string.统计target在source中出现的次数。
|
static String |
deleteIgnoreCase(String source,
String target)
Returns a new string which source string delete destination chars ignore
case sensitive.
|
static String |
encoding(String source,
String sourceCharset,
String encodingCharset)
Return encoded string by given charset.
|
static boolean |
endsWithIgnoreCase(String source,
String target)
Returns true if given source string end with target string ignore case
sensitive; false otherwise.
|
static String |
firstCharToLowerCase(String source)
Convert first character in given string to lower case.
If given source string is blank or first character is lower case, return it's self. |
static String |
firstCharToUpperCase(String source)
Convert first character in given string to upper case.
If given source string is blank or first character is upper case, return it's self. |
static char |
getRandomAlphabetic()
Returns a random alphabetic: a-zA-Z.
|
static char |
getRandomLowerCaseAlphabetic()
Returns a random alphabetic: a-zA-Z.
|
static char |
getRandomPasswordChar()
Returns a random passowrd char: a-zA-Z0-9.
|
static String |
getRandomPasswordString(int stringLength)
Returns a random given length size passowrd string([a-zA-Z0-9]+).
|
static String |
getRandomString(int stringLength)
Returns a random given length size alphabetic string.
|
static char |
getRandomUpperCaseAlphabetic()
Returns a random alphabetic: a-zA-Z.
|
static List<String> |
getStringsByRegex(String text,
String regex)
根据正则表达式提取字符串
|
static List<String> |
getWords(String text,
int wordMinimumLength)
Returns words in given text by given word minimum length.
|
static int |
indexOfIgnoreCase(String source,
String target)
Returns the index within given source string of the first occurrence of
the specified target string with ignore case sensitive.
|
static int |
indexOfIgnoreCase(String source,
String target,
int fromIndex)
Returns the index within given source string of the first occurrence of
the specified target string with ignore case sensitive, starting at the
specify index.
|
static boolean |
isBlank(String source)
Returns true if the source string is null or all characters in this
string is space; false otherwise.
|
static boolean |
isEmpty(String source)
Returns true if the source string is null or length = 0; false otherwise.
|
static boolean |
isNotBlank(String source)
Returns true if the source string is not null and at least one character
in this string is not space; false otherwise.
|
static String |
replacIgnoreCase(String source,
String target,
String replacement)
Replaces each substring of given source string that matches the given
regular expression ignore case sensitive with the given replacement.
|
static String |
reverse(String string)
Sort the array in reverse order.反转字符串。
|
static boolean |
startsWithIgnoreCase(String source,
String target)
Returns true if given source string start with target string ignore case
sensitive; false otherwise.
|
static String |
trimAllWhitespace(String source)
Trim all white space in the given string.
If given source string self if it's null or length == 0 or not have white space. |
public static final int INDEX_OF_NOT_FOUND
public static boolean isEmpty(String source)
source - string to be tested.public static boolean isBlank(String source)
source - string to be tested.public static boolean isNotBlank(String source)
source - string to be tested.public static String firstCharToUpperCase(String source)
source - string to be tested.public static String firstCharToLowerCase(String source)
source - string want to be handle.public static int indexOfIgnoreCase(String source, String target)
source - source string to be tested.target - target string to be tested.public static int indexOfIgnoreCase(String source, String target, int fromIndex)
source - source string to be tested.target - target string to be tested.public static boolean containsWhitespace(String source)
source - string to be tested.public static boolean containsIgnoreCase(String source, String target)
source - string to be tested.target - string to be tested.public static List<String> getWords(String text, int wordMinimumLength)
e.g:
text: "I have a dream, but now it is only a dream."
wordMinimumLength: 2
result:["have","dream","but","now","it","is","only","dream"].
NB. "1word","word1" also were words.
text - source string to be handled.wordMinimumLength - word minimum length to partition.public static List<String> getStringsByRegex(String text, String regex)
text - 源字符串regex - 正则表达式public static boolean containsWord(String text, String word)
text - string text to be tested.word - string word to be tested.public static boolean containsWordIgnoreCase(String text, String word)
text - string text to be tested.word - string word to be tested.public static String trimAllWhitespace(String source)
source - public static boolean startsWithIgnoreCase(String source, String target)
source - string to be tested.target - string to be tested.public static boolean endsWithIgnoreCase(String source, String target)
source - string to be tested.target - string to be tested.public static String replacIgnoreCase(String source, String target, String replacement)
source - source string want to be handle.target - target string want to be replaces.replacement - string of replace to.public static String deleteIgnoreCase(String source, String target)
source - source want to be handle.target - target string want to be deleted.public static char getRandomUpperCaseAlphabetic()
public static char getRandomLowerCaseAlphabetic()
public static char getRandomAlphabetic()
public static String getRandomString(int stringLength)
stringLength - the length of the random string you want.public static char getRandomPasswordChar()
public static String getRandomPasswordString(int stringLength)
stringLength - the length of the random passowrd you want.public static String encoding(String source, String sourceCharset, String encodingCharset) throws IllegalArgumentException
source - source string to be handle.sourceCharset - source string charset name.encodingCharset - want encoding to which charset.IllegalArgumentExceptionWORD_PATTERN - If the named charset is not supportedIllegalArgumentExceptionpublic static String reverse(String string)
string - string to be handled.public static int count(String source, String target)
source - source stringtarget - target stringCopyright © 2014. All rights reserved.