static String |
abbreviate(String str, int maxWidth) Abbreviates a String using ellipses. |
可以返回长度为maxWidth的String,最右侧会使用...
觉得这个方法没啥用
static String |
center(String str, int size, char padChar) Centers a String in a larger String of size size |
返回一个一个长度为size的字符串,原字符串居中(偏前),其他用padChar填充,若无此参数则使用" "填充
应该是一个有用的方法,另外这个方法重载,第三个参数可以是String,不过觉得没用
static String |
chomp(String str) Removes one newline from end of a String if it's there, otherwise leave it alone |
将一个字符串末尾的换行符(/r 、/n、 /r/n)去掉。如果有多个则只去掉一次,注意/n/r只会去掉/r
static String |
chop(String str) Remove the last character from a String |
去掉最后一个字符
static boolean |
contains(CharSequence seq, CharSequence searchSeq) Checks if CharSequence contains a search CharSequence, handling null . |
查询seq是否包括searchSeq,我查看该方法才知道CharSequence是一个借口,String,StringBuilder,StringBuffer都实现了该接口。该方法重载,第二个参数也可以是char
static boolean |
containsAny(CharSequence cs, CharSequence searchChars) Checks if the CharSequence contains any character in the given set of characters. |
查询cs是否包括searchChars的任意char(从any可以看出来),另外该方法重载,第二个参数可以是可变长参数char
static boolean |
containsIgnoreCase(CharSequence str, CharSequence searchStr) Checks if CharSequence contains a search CharSequence irrespective of case, handling null . |
上上个方法忽略大小写
static boolean |
containsNone(CharSequence cs, char... searchChars) Checks that the CharSequence does not contain certain characters. |
与前面的方法相反,这里是没有包括,另外第二个参数可以为String
static boolean |
containsOnly(CharSequence cs, char... valid) Checks if the CharSequence contains only certain characters. |
第二个参数可以为String
static boolean |
containsWhitespace(CharSequence seq) Check whether the given CharSequence contains any whitespace characters. |
static int |
countMatches(CharSequence str, CharSequence sub) Counts how many times the substring appears in the larger string. |
可以数出现多少次,觉得完胜前面返回boolean的方法啊
static String |
defaultString(String str, String defaultStr) Returns either the passed in String, or if the String is null , the value of defaultStr . |
当输入为null时转为defaultStr,这个应该很容易实现,另外这个方法重载,觉得没必要
static String |
difference(String str1, String str2) Compares two Strings, and returns the portion where they differ. |
得到str2中不同于前者的部分,如果两个都是null则返回null,完全相同则是“”(注意str也为“”时)
static boolean |
endsWith(CharSequence str, CharSequence suffix) Check if a CharSequence ends with a specified suffix. |
static boolean |
endsWithAny(CharSequence string, CharSequence... searchStrings) Check if a CharSequence ends with any of an array of specified strings. |
static boolean |
endsWithIgnoreCase(CharSequence str, CharSequence suffix) Case insensitive check if a CharSequence ends with a specified suffix. |
比较一个字符串是否怎样结尾。
static boolean |
equalsIgnoreCase(CharSequence str1, CharSequence str2) Compares two CharSequences, returning true if they are equal ignoring the case. |
忽略大小写比较
static String |
getCommonPrefix(String... strs) Compares all Strings in an array and returns the initial sequence of characters that is common to all of them. |
得到公有String,null作为参数会被视为“”
static int |
indexOf(CharSequence seq, CharSequence searchSeq, int startPos) Finds the first index within a CharSequence, handling null . |
寻找是否有子字符串,第二个参数可以为char,第三个参数可以没有
还可以用lastIndexOf()找最后一个
static int |
indexOfAny(CharSequence cs, char... searchChars) Search a CharSequence to find the first index of any character in the given set of characters. |
static int |
indexOfAny(CharSequence str, CharSequence... searchStrs) Find the first index of any of a set of potential substrings. |
static int |
indexOfAny(CharSequence cs, String searchChars) Search a CharSequence to find the first index of any character in the given set of characters. |
static int |
indexOfAnyBut(CharSequence cs, char... searchChars) Searches a CharSequence to find the first index of any character not in the given set of characters. |
static int |
indexOfAnyBut(CharSequence seq, CharSequence searchChars) Search a CharSequence to find the first index of any character not in the given set of characters. |
寻找没有出现的char
static int |
indexOfDifference(CharSequence... css) Compares all CharSequences in an array and returns the index at which the CharSequences begin to differ. |
寻找不一样的地方
static int |
indexOfIgnoreCase(CharSequence str, CharSequence searchStr, int startPos) Case in-sensitive find of the first index within a CharSequence from the specified position. |
忽略大小写并可以指定位置
static boolean |
isAllLowerCase(CharSequence cs) Checks if the CharSequence contains only lowercase characters. |
static boolean |
isAllUpperCase(CharSequence cs) Checks if the CharSequence contains only uppercase characters. |
static boolean |
isAlpha(CharSequence cs) Checks if the CharSequence contains only Unicode letters. |
static boolean |
isAlphanumeric(CharSequence cs) Checks if the CharSequence contains only Unicode letters or digits. |
static boolean |
isAlphanumericSpace(CharSequence cs) Checks if the CharSequence contains only Unicode letters, digits or space ( ' ' ). |
static boolean |
isAlphaSpace(CharSequence cs) Checks if the CharSequence contains only Unicode letters and space (' '). |
static boolean |
isAsciiPrintable(CharSequence cs) Checks if the CharSequence contains only ASCII printable characters. |
static boolean |
isBlank(CharSequence cs) Checks if a CharSequence is whitespace, empty ("") or null. |
static boolean |
isEmpty(CharSequence cs) Checks if a CharSequence is empty ("") or null. |
static boolean |
isNotBlank(CharSequence cs) Checks if a CharSequence is not empty (""), not null and not whitespace only. |
static boolean |
isNotEmpty(CharSequence cs) Checks if a CharSequence is not empty ("") and not null. |
static boolean |
isNumeric(CharSequence cs) Checks if the CharSequence contains only Unicode digits. |
static boolean |
isNumericSpace(CharSequence cs) Checks if the CharSequence contains only Unicode digits or space ( ' ' ). |
static boolean |
isWhitespace(CharSequence cs) Checks if the CharSequence contains only whitespace |
static String |
join(Iterable<?> iterable, char separator) Joins the elements of the provided Iterable into a single String containing the provided elements. |
static String |
join(Iterable<?> iterable, String separator) Joins the elements of the provided Iterable into a single String containing the provided elements. |
将一组东西拼接起来,第一个参数可以是Object[]
static
|
join(T... elements) Joins the elements of the provided array into a single String containing the provided list of elements. |
static String |
left(String str, int len) Gets the leftmost len characters of a String. |
static String |
leftPad(String str, int size) Left pad a String with spaces (' '). |
static String |
leftPad(String str, int size, char padChar) Left pad a String with a specified character. |
static String |
leftPad(String str, int size, String padStr) Left pad a String with a specified String. |
static String |
mid(String str, int pos, int len) Gets len characters from the middle of a String. |
static int |
ordinalIndexOf(CharSequence str, CharSequence searchStr, int ordinal) Finds the n-th index within a CharSequence, handling null . |
寻找第n次出现的位置
static String |
overlay(String str, String overlay, int start, int end) Overlays part of a String with another String. |
覆盖
static String |
remove(String str, char remove) Removes all occurrences of a character from within the source string. |
static String |
remove(String str, String remove) Removes all occurrences of a substring from within the source string. |
移除
static String |
removeEnd(String str, String remove) Removes a substring only if it is at the end of a source string, otherwise returns the source string. |
static String |
removeEndIgnoreCase(String str, String remove) Case insensitive removal of a substring if it is at the end of a source string, otherwise returns the source string. |
static String |
removeStart(String str, String remove) Removes a substring only if it is at the beginning of a source string, otherwise returns the source string. |
static String |
removeStartIgnoreCase(String str, String remove) Case insensitive removal of a substring if it is at the beginning of a source string, otherwise returns the source string. |
static String |
repeat(char ch, int repeat) Returns padding using the specified delimiter repeated to a given length. |
static String |
repeat(String str, int repeat) Repeat a String repeat times to form a new String. |
static String |
repeat(String str, String separator, int repeat) Repeat a String repeat times to form a new String, with a String separator injected each time. |
static String |
replace(String text, String searchString, String replacement) Replaces all occurrences of a String within another String. |
static String |
replace(String text, String searchString, String replacement, int max) Replaces a String with another String inside a larger String, for the first max values of the search String. |
static String |
replaceChars(String str, char searchChar, char replaceChar) Replaces all occurrences of a character in a String with another. |
static String |
replaceChars(String str, String searchChars, String replaceChars) Replaces multiple characters in a String in one go. |
替换,如果后面长度不够则重复补齐,如果超了则丢弃
static String |
replaceOnce(String text, String searchString, String replacement) Replaces a String with another String inside a larger String, once. |
static String |
reverseDelimited(String str, char separatorChar) Reverses a String that is delimited by a specific character. |
从一个分割位开始反转
static String[] |
split(String str, String separatorChars, int max) Splits the provided text into an array with a maximum length, separators specified. |
max是指定分割后数组长度,可以为0,就相当于没有,也就是无次数限制
static boolean |
startsWith(CharSequence str, CharSequence prefix) Check if a CharSequence starts with a specified prefix. |
static boolean |
startsWithAny(CharSequence string, CharSequence... searchStrings) Check if a CharSequence starts with any of an array of specified strings. |
static boolean |
startsWithIgnoreCase(CharSequence str, CharSequence prefix) Case insensitive check if a CharSequence starts with a specified prefix. |
static String |
strip(String str) Strips whitespace from the start and end of a String. |
static String |
strip(String str, String stripChars) Strips any of a set of characters from the start and end of a String. |
static String[] |
stripAll(String... strs) Strips whitespace from the start and end of every String in an array. |
static String[] |
stripAll(String[] strs, String stripChars) Strips any of a set of characters from the start and end of every String in an array. |
批量strip
static String |
stripEnd(String str, String stripChars) Strips any of a set of characters from the end of a String. |
static String |
stripStart(String str, String stripChars) Strips any of a set of characters from the start of a String. |
static String |
stripToEmpty(String str) Strips whitespace from the start and end of a String returning an empty String if null input. |
static String |
stripToNull(String str) Strips whitespace from the start and end of a String returning null if the String is empty ("") after the strip. |
static String |
substringAfter(String str, String separator) Gets the substring after the first occurrence of a separator. |
static String |
substringAfterLast(String str, String separator) Gets the substring after the last occurrence of a separator. |
static String |
substringBefore(String str, String separator) Gets the substring before the first occurrence of a separator. |
static String |
substringBeforeLast(String str, String separator) Gets the substring before the last occurrence of a separator. |
static String |
substringBetween(String str, String tag) Gets the String that is nested in between two instances of the same String. |
static String |
substringBetween(String str, String open, String close) Gets the String that is nested in between two Strings. |
static String[] |
substringsBetween(String str, String open, String close) Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array. |
各种截取
static String |
swapCase(String str) Swaps the case of a String changing upper and title case to lower case, and lower case to upper case. |
反转大小写
static String |
trim(String str) Removes control characters (char <= 32) from both ends of this String, handling null by returning null . |
static String |
trimToEmpty(String str) Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null . |
static String |
trimToNull(String str) Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null . |