Commons_Lang_StringUtils学习笔记

 

static Stringabbreviate(String str,                     int maxWidth)
          Abbreviates a String using ellipses.

可以返回长度为maxWidth的String,最右侧会使用...

觉得这个方法没啥用

 

 

static Stringcenter(String str,             int size,             char padChar)
          Centers a String in a larger String of size size

返回一个一个长度为size的字符串,原字符串居中(偏前),其他用padChar填充,若无此参数则使用" "填充

应该是一个有用的方法,另外这个方法重载,第三个参数可以是String,不过觉得没用

 

 

static Stringchomp(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 Stringchop(String str)
          Remove the last character from a String

去掉最后一个字符

 

 

static booleancontains(CharSequence seq,                  CharSequence searchSeq)
          Checks if CharSequence contains a search CharSequence, handling null.

查询seq是否包括searchSeq,我查看该方法才知道CharSequence是一个借口,String,StringBuilder,StringBuffer都实现了该接口。该方法重载,第二个参数也可以是char

 

 

static booleancontainsAny(CharSequence cs,                        CharSequence searchChars)
           Checks if the CharSequence contains any character in the given set of characters.

查询cs是否包括searchChars的任意char(从any可以看出来),另外该方法重载,第二个参数可以是可变长参数char

 

 

static booleancontainsIgnoreCase(CharSequence str,                                      CharSequence searchStr)
          Checks if CharSequence contains a search CharSequence irrespective of case, handling null.

上上个方法忽略大小写

 

 

static booleancontainsNone(CharSequence cs,                         char... searchChars)
          Checks that the CharSequence does not contain certain characters.

与前面的方法相反,这里是没有包括,另外第二个参数可以为String

 

static booleancontainsOnly(CharSequence cs,                         char... valid)
          Checks if the CharSequence contains only certain characters.

第二个参数可以为String

 

 

static booleancontainsWhitespace(CharSequence seq)
          Check whether the given CharSequence contains any whitespace characters.

 

static intcountMatches(CharSequence str,                          CharSequence sub)
          Counts how many times the substring appears in the larger string.

可以数出现多少次,觉得完胜前面返回boolean的方法啊

 

static StringdefaultString(String str,                            String defaultStr)
          Returns either the passed in String, or if the String is  null, the value of defaultStr.

当输入为null时转为defaultStr,这个应该很容易实现,另外这个方法重载,觉得没必要

 

static Stringdifference(String str1,                      String str2)
          Compares two Strings, and returns the portion where they differ.

得到str2中不同于前者的部分,如果两个都是null则返回null,完全相同则是“”(注意str也为“”时)

 

static booleanendsWith(CharSequence str,                  CharSequence suffix)
          Check if a CharSequence ends with a specified suffix.
static booleanendsWithAny(CharSequence string,                        CharSequence... searchStrings)
          Check if a CharSequence ends with any of an array of specified strings.
static booleanendsWithIgnoreCase(CharSequence str,                                      CharSequence suffix)
          Case insensitive check if a CharSequence ends with a specified suffix.

比较一个字符串是否怎样结尾。

 

 

static booleanequalsIgnoreCase(CharSequence str1,                                  CharSequence str2)
          Compares two CharSequences, returning true if they are equal ignoring the case.

忽略大小写比较

 

 

static StringgetCommonPrefix(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 intindexOf(CharSequence seq,                CharSequence searchSeq,               int startPos)
          Finds the first index within a CharSequence, handling null.

寻找是否有子字符串,第二个参数可以为char,第三个参数可以没有

还可以用lastIndexOf()找最后一个

 

 

static intindexOfAny(CharSequence cs,                     char... searchChars)
          Search a CharSequence to find the first index of any character in the given set of characters.
static intindexOfAny(CharSequence str,                      CharSequence... searchStrs)
          Find the first index of any of a set of potential substrings.
static intindexOfAny(CharSequence cs,                      String searchChars)
          Search a CharSequence to find the first index of any character in the given set of characters.

 

static intindexOfAnyBut(CharSequence cs,                           char... searchChars)
          Searches a CharSequence to find the first index of any character not in the given set of characters.
static intindexOfAnyBut(CharSequence seq,                            CharSequence searchChars)
          Search a CharSequence to find the first index of any character not in the given set of characters.

寻找没有出现的char

 

 

static intindexOfDifference(CharSequence... css)
          Compares all CharSequences in an array and returns the index at which the CharSequences begin to differ.

寻找不一样的地方

 

static intindexOfIgnoreCase(CharSequence str,                                    CharSequence searchStr,                                   int startPos)
          Case in-sensitive find of the first index within a CharSequence from the specified position.

忽略大小写并可以指定位置

 

static booleanisAllLowerCase(CharSequence cs)
          Checks if the CharSequence contains only lowercase characters.
static booleanisAllUpperCase(CharSequence cs)
          Checks if the CharSequence contains only uppercase characters.
static booleanisAlpha(CharSequence cs)
          Checks if the CharSequence contains only Unicode letters.
static booleanisAlphanumeric(CharSequence cs)
          Checks if the CharSequence contains only Unicode letters or digits.
static booleanisAlphanumericSpace(CharSequence cs)
          Checks if the CharSequence contains only Unicode letters, digits or space (' ').
static booleanisAlphaSpace(CharSequence cs)
          Checks if the CharSequence contains only Unicode letters and space (' ').
static booleanisAsciiPrintable(CharSequence cs)
          Checks if the CharSequence contains only ASCII printable characters.
static booleanisBlank(CharSequence cs)
          Checks if a CharSequence is whitespace, empty ("") or null.
static booleanisEmpty(CharSequence cs)
          Checks if a CharSequence is empty ("") or null.
static booleanisNotBlank(CharSequence cs)
          Checks if a CharSequence is not empty (""), not null and not whitespace only.
static booleanisNotEmpty(CharSequence cs)
          Checks if a CharSequence is not empty ("") and not null.
static booleanisNumeric(CharSequence cs)
          Checks if the CharSequence contains only Unicode digits.
static booleanisNumericSpace(CharSequence cs)
          Checks if the CharSequence contains only Unicode digits or space (' ').
static booleanisWhitespace(CharSequence cs)
          Checks if the CharSequence contains only whitespace

 

 

static Stringjoin(Iterable<?> iterable,         char separator)
          Joins the elements of the provided Iterable into a single String containing the provided elements.
static Stringjoin(Iterable<?> iterable,          String separator)
          Joins the elements of the provided Iterable into a single String containing the provided elements.

 

将一组东西拼接起来,第一个参数可以是Object[]

 

static
<T> String
join(T... elements)
          Joins the elements of the provided array into a single String containing the provided list of elements.

 

 

static Stringleft(String str,         int len)
          Gets the leftmost len characters of a String.

 

static StringleftPad(String str,               int size)
          Left pad a String with spaces (' ').
static StringleftPad(String str,               int size,               char padChar)
          Left pad a String with a specified character.
static StringleftPad(String str,               int size,                String padStr)
          Left pad a String with a specified String.

 

static Stringmid(String str,       int pos,       int len)
          Gets len characters from the middle of a String.

 

static intordinalIndexOf(CharSequence str,                              CharSequence searchStr,                             int ordinal)
          Finds the n-th index within a CharSequence, handling null.

寻找第n次出现的位置

 

static Stringoverlay(String str,                String overlay,               int start,               int end)
          Overlays part of a String with another String.

覆盖

 

static Stringremove(String str,             char remove)
          Removes all occurrences of a character from within the source string.
static Stringremove(String str,              String remove)
          Removes all occurrences of a substring from within the source string.

 

移除

 

static StringremoveEnd(String str,                    String remove)
          Removes a substring only if it is at the end of a source string, otherwise returns the source string.
static StringremoveEndIgnoreCase(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 StringremoveStart(String str,                        String remove)
          Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
static StringremoveStartIgnoreCase(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 Stringrepeat(char ch,             int repeat)
          Returns padding using the specified delimiter repeated to a given length.
static Stringrepeat(String str,             int repeat)
          Repeat a String repeat times to form a new String.
static Stringrepeat(String str,              String separator,             int repeat)
          Repeat a String repeat times to form a new String, with a String separator injected each time.

 

static Stringreplace(String text,                String searchString,                String replacement)
          Replaces all occurrences of a String within another String.
static Stringreplace(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 StringreplaceChars(String str,                         char searchChar,                         char replaceChar)
          Replaces all occurrences of a character in a String with another.
static StringreplaceChars(String str,                          String searchChars,                          String replaceChars)
          Replaces multiple characters in a String in one go.

 

替换,如果后面长度不够则重复补齐,如果超了则丢弃

 

 

static StringreplaceOnce(String text,                        String searchString,                        String replacement)
          Replaces a String with another String inside a larger String, once.

 

static StringreverseDelimited(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 booleanstartsWith(CharSequence str,                      CharSequence prefix)
          Check if a CharSequence starts with a specified prefix.
static booleanstartsWithAny(CharSequence string,                            CharSequence... searchStrings)
          Check if a CharSequence starts with any of an array of specified strings.
static booleanstartsWithIgnoreCase(CharSequence str,                                          CharSequence prefix)
          Case insensitive check if a CharSequence starts with a specified prefix.

 

static Stringstrip(String str)
          Strips whitespace from the start and end of a String.
static Stringstrip(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 StringstripEnd(String str,                  String stripChars)
          Strips any of a set of characters from the end of a String.
static StringstripStart(String str,                      String stripChars)
          Strips any of a set of characters from the start of a String.
static StringstripToEmpty(String str)
          Strips whitespace from the start and end of a String  returning an empty String if null input.
static StringstripToNull(String str)
          Strips whitespace from the start and end of a String  returning  null if the String is empty ("") after the strip.

 

static StringsubstringAfter(String str,                              String separator)
          Gets the substring after the first occurrence of a separator.
static StringsubstringAfterLast(String str,                                      String separator)
          Gets the substring after the last occurrence of a separator.
static StringsubstringBefore(String str,                                String separator)
          Gets the substring before the first occurrence of a separator.
static StringsubstringBeforeLast(String str,                                        String separator)
          Gets the substring before the last occurrence of a separator.
static StringsubstringBetween(String str,                                  String tag)
          Gets the String that is nested in between two instances of the same String.
static StringsubstringBetween(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 StringswapCase(String str)
          Swaps the case of a String changing upper and title case to lower case, and lower case to upper case.

反转大小写

 

static Stringtrim(String str)
          Removes control characters (char <= 32) from both ends of this String, handling null by returning  null.
static StringtrimToEmpty(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 StringtrimToNull(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.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值