StringUtils 中文API

由於本人水平有限,翻譯可能不太準確,先把部分原稿發佈,還沒有進行校對,請大家提寶貴意見,

近期發佈api

org.apache.commons.lang 
Class StringUtils

java.lang.Object

  org.apache.commons.lang.StringUtils


public class StringUtils

extends Object

Operations on String that are null safe. 字符串是null安全的,不會拋出NullPointerException,都做了相應的處理。

  • IsEmpty/IsBlank - checks if a String contains text
  • IsEmpty/IsBlank – 檢查字符串是否有內容。
  • Trim/Strip - removes leading and trailing whitespace
  • Trim/Strip – 刪除字符串開始和結尾的空白符。
  • Equals - compares two strings null-safe
  • Equals – 比較兩個字符串null安全。
  • IndexOf/LastIndexOf/Contains - null-safe index-of checks
  • IndexOf/LastIndexOf/Contains – null安全的索引檢查。
  • IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut - index-of any of a set of Strings
  • IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut – 字符串集合索引檢查。
  • ContainsOnly/ContainsNone - does String contains only/none of these characters
  • ContainsOnly/ContainsNone – 字符在字符串中出現一次或一次也沒有出現。
  • Substring/Left/Right/Mid - null-safe substring extractions
  • Substring/Left/Right/Mid – null安全子串的提取。
  • SubstringBefore/SubstringAfter/SubstringBetween - substring extraction relative to other strings
  • SubstringBefore/SubstringAfter/SubstringBetween – 子串提取依賴其它字符串。
  • Split/Join - splits a String into an array of substrings and vice versa
  • Split/Join – 字符串拆分爲子串的字符串數組,反之亦然。
  • Remove/Delete - removes part of a String
  • Remove/Delete – 刪除部分字符串。
  • Replace/Overlay - Searches a String and replaces one String with another
  • Replace/Overlay – 替換字符串的部分字符。
  • Chomp/Chop - removes the last part of a String
  • Chomp/Chop – 刪除字符串最後的字符。
  • LeftPad/RightPad/Center/Repeat - pads a String
  • LeftPad/RightPad/Center/Repeat – 補字符串。
  • UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize - changes the case of a String
  • UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize – 改變字符串的大小寫。
  • CountMatches - counts the number of occurrences of one String in another
  • CountMatches – 計算一個字符或字符串在另外一個字符串出現的次數。
  • IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable - checks the characters in a String
  • IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable – 判斷字符是否在字符串中。
  • DefaultString - protects against a null input String
  • DefaultString –null安全,null轉換爲字符串。
  • Reverse/ReverseDelimited - reverses a String
  • Reverse/ReverseDelimited – 反轉字符串。
  • Abbreviate - abbreviates a string using ellipsis
  • Abbreviate – 縮寫字符串用省略符。
  • Difference - compares two Strings and reports on their differences
  • Difference – 比較兩個字符串並且返回不同。
  • LevensteinDistance - the number of changes needed to change one String into another
  • LevensteinDistance – 一個字符串改變爲另一個字符串需要改變的數量。

The StringUtils class defines certain words related to String handling.

StringUtils類是對字符串的處理。

  • null – null 空
  • empty - a zero-length string ("") 長度爲0的字符串
  • space - the space character (' ', char 32) 間隔符
  • whitespace - the characters defined by Character.isWhitespace(char) 空格符
  • trim - the characters <= 32 as in String.trim()去掉字符串兩邊字符<=32

Version:

$Id: StringUtils.Java 492377 2007-01-04 01:20:30Z scolebourne $

 

Field Summary字段摘要

static String

EMPTY 
          The empty String "".空字符串。

static int

INDEX_NOT_FOUND 
          Represents a failed index search. 聲明失敗索引。

 

Constructor Summary構造方法摘要

StringUtils() 
          StringUtils instances should NOT be constructed in standard programming.StringUtils 所有方法都是靜態方法,不能在程序中對其進行構造。

 

 

Method Summary方法摘要

static String

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

取得字符串的縮寫,str:處理的字符串,maxWidth:寬度,從第一個字符開始[1,maxWidth),類似於substring(),返回一個新的字符串,它是此字符串的一個子字符串。

static String

abbreviate(String str, int offset, int maxWidth) 
          Abbreviates a String using ellipses.

取得字符串的縮寫,str:處理的字符串,maxWidth:寬度,從第offset個字符開始[offset,axWidth),類似於substring(),返回一個新的字符串,它是此字符串的一個子字符串。

static String

capitalise(String str) 
          Deprecated. Use the standardly named capitalize(String). Method will be removed in Commons Lang 3.0.

過時了.用 capitalize(String),在Commons Lang 3.0已經沒有此方法了。

static String

capitaliseAllWords(String str) 
          Deprecated. Use the relocated WordUtils.capitalize(String). Method will be removed in Commons Lang 3.0.

過時了. 在Commons Lang 3.0已經沒有此方法了。

static String

capitalize(String str) 
          Capitalizes a String changing the first letter to title case as per Character.toTitleCase(char).

將str手寫字母大寫,用於名稱、頭銜等

static String

center(String str, int size) 
          Centers a String in a larger String of size size using the space character (' ').

產生一個字符串返回,該字符串長度等於sizestr位於新串的中心,其他位置補空格。
如果strnull,則返回null
如果size小於str的長度,則返回str本身

static String

center(String str, int size, char padChar) 
          Centers a String in a larger String of size size.

產生一個字符串返回,該字符串長度等於sizestr位於新串的中心,其他位置補字符padChar
如果strnull,則返回null
如果size小於str的長度,則返回str本身

static String

center(String str, int size, String padStr) 
          Centers a String in a larger String of size size.

產生一個字符串返回,該字符串長度等於sizestr位於新串的中心,其他位置補字符串padStr
如果strnull,則返回null
如果size小於str的長度,則返回str本身

static String

chomp(String str) 
          Removes one newline from end of a String if it's there, otherwise leave it alone.

 以單個詞爲單位的反轉

str=”I am yuanyuan !”;

chomp(str)=”! yuanyuan an  I”;

static String

chomp(String str, String separator) 
          Removes separator from the end of str if it's there, otherwise leave it alone.

 以單個詞爲單位的反轉,從separator開始

str=”I am yuanyuan !”;

chomp(str ,”!”)=” yuanyuan an  I !”;

static String

chompLast(String str) 
          Deprecated. Use chomp(String) instead. Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

chompLast(String str, String sep) 
          Deprecated. Use chomp(String,String) instead. Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

chop(String str) 
          Remove the last character from a String.

去掉字符串str的最後一個字符。如果字符串以"/r/n"結尾,則去掉它們。

static String

chopNewline(String str) 
          Deprecated. Use chomp(String) instead. Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

clean(String str) 
          Deprecated. Use the clearer named trimToEmpty(String). Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

concatenate(Object[] array) 
          Deprecated. Use the better named join(Object[]) instead. Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static boolean

contains(String str, char searchChar) 
          Checks if String contains a search character, handling null.

當此字符串包含指定的字符searchChar 值序列時,返回 true;處理null。

static boolean

contains(String str, String searchStr) 
          Checks if String contains a search String, handling null.

當此字符串包含指定的字符串searchStr 值序列時,返回 true;處理null。

static boolean

containsIgnoreCase(String str, String searchStr) 
          Checks if String contains a search String irrespective of case, handling null.

當此字符串包含指定的字符串searchStr 值序列時,忽略大小寫,返回 true;處理null。

static boolean

containsNone(String str, char[] invalidChars) 
          Checks that the String does not contain certain characters.

判斷是否字符串str不包含字符數組invalidChars中的字符,如果含有則返回false。

static boolean

containsNone(String str, String invalidChars) 
          Checks that the String does not contain certain characters.

判斷是否字符串str不包含字符串invalidChars,如果含有則返回false。

static boolean

containsOnly(String str, char[] valid) 
          Checks if the String contains only certain characters.

判斷是否字符串str包含字符數組valid中的字符,如果含有則返回true。

static boolean

containsOnly(String str, String validChars) 
          Checks if the String contains only certain characters.

判斷是否字符串str包含字符串invalidChars,如果含有則返回true。

static int

countMatches(String str, String sub) 
          Counts how many times the substring appears in the larger String.

計算字符串sub在字符串str中出現的次數。如果strnull"",則返回0

static String

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

如果str不是空或者null,返回str,否則返回defaultStr。

static String

defaultString(String str) 
          Returns either the passed in String, or if the String is null, an empty String ("").

如果str不是空返回str,否則返回""。

static String

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

如果str不爲空,返回str,否則返回defaultStr

static String

deleteSpaces(String str) 
          Deprecated. Use the better localized deleteWhitespace(String). Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

deleteWhitespace(String str) 
          Deletes all whitespaces from a String as defined by Character.isWhitespace(char).

刪除字符串中的所有空白符

static String

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

比較兩個字符串,返回不同的部分。

static boolean

equals(String str1, String str2) 
          Compares two Strings, returning true if they are equal.

比較兩個字符串是否相等。

static boolean

equalsIgnoreCase(String str1, String str2) 
          Compares two Strings, returning true if they are equal ignoring the case.

比較兩個字符串是否相等,區分大小寫。

static String

escape(String str) 
          Deprecated. Use StringEscapeUtils.escapeJava(String) This method will be removed in Commons Lang 3.0

過時了.Commons Lang 3.0已經沒有此方法了

static String

getChomp(String str, String sep) 
          Deprecated. Use substringAfterLast(String, String) instead (although this doesn't include the separator) Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static int

getLevenshteinDistance(String s, String t) 
          Find the Levenshtein distance between two Strings.

計算兩個字符串 levenshtein 距離,在計算相似度是用到這個方法

static String

getNestedString(String str, String tag) 
          Deprecated. Use the better named substringBetween(String, String). Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

getNestedString(String str, String open, String close) 
          Deprecated. Use the better named substringBetween(String, String, String). Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

getPrechomp(String str, String sep) 
          Deprecated. Use substringBefore(String,String) instead (although this doesn't include the separator). Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static int

indexOf(String str, char searchChar) 
          Finds the first index within a String, handling null.

返回字符searchChar在字符串str中第一次出現的位置。
如果searchChar沒有在str中出現則返回-1,
如果str爲null或"",則也返回-1

static int

indexOf(String str, char searchChar, int startPos) 
          Finds the first index within a String from a start position, handling null.

返回字符searchChar從startPos開始在字符串str中第一次出現的位置。
如果從startPos開始searchChar沒有在str中出現則返回-1,
如果str爲null或"",則也返回-1

static int

indexOf(String str, String searchStr) 
          Finds the first index within a String, handling null.

返回字符串searchStr在字符串str中第一次出現的位置。
如果str爲null或searchStr爲null則返回-1,
如果searchStr爲"",且str爲不爲null,則返回0,
如果searchStr不在str中,則返回-1

static int

indexOf(String str, String searchStr, int startPos) 
          Finds the first index within a String, handling null.

返回字符串searchStrr從startPos開始在字符串str中第一次出現的位置。
如果從startPos開始searchStrr沒有在str中出現則返回-1,
如果str爲null或"",則也返回-1

static int

indexOfAny(String str, char[] searchChars) 
          Search a String to find the first index of any character in the given set of characters.

找出字符數組searchChars中的字符第一次出現在字符串str中的位置。 
如果字符數組中的字符都不在字符串中,則返回-1 
如果字符串爲null或"",則返回-1 

static int

indexOfAny(String str, String searchChars) 
          Search a String to find the first index of any character in the given set of characters.

找出字符串searchChars中的字符第一次出現在字符串str中的位置。 
如果字符串searchChars中的字符都不在字符串str中,則返回-1 
如果searchChars或str爲null或爲"",則返回-1 

static int

indexOfAny(String str, String[] searchStrs) 
          Find the first index of any of a set of potential substrings.

找出字符數組searchStrs中的字符串第一次出現在字符串str中的位置。 
如果字符串數組searchStrs中的字符都不在字符串str中,則返回-1 
如果searchStrs或str爲null或爲"",則返回-1 

static int

indexOfAnyBut(String str, char[] searchChars) 
          Search a String to find the first index of any character not in the given set of characters.

找出字符串str中不在字符數組searchChars中的第一個字符的位置。 
如果字符串中的所有字符都在字符數組中,則返回-1 
如果字符串爲null或"",則返回-1 

static int

indexOfAnyBut(String str, String searchChars) 
          Search a String to find the first index of any character not in the given set of characters.

找出字符串str中不在字符串searchChars中的第一個字符的位置。 
如果字符串str中的所有字符都在字符串searchChars中,則返回-1 
如果字符串str或searchChars爲null或"",則返回-1 

static int

indexOfDifference(String str1, String str2) 
          Compares two Strings, and returns the index at which the Strings begin to differ.

比較兩個字符串,返回第一次不同的位置。

static boolean

isAlpha(String str) 
          Checks if the String contains only unicode letters.

判斷Str是否由字母組成。

static boolean

isAlphanumeric(String str) 
          Checks if the String contains only unicode letters or digits.

判斷Str是否由字母或數字組成。

static boolean

isAlphanumericSpace(String str) 
          Checks if the String contains only unicode letters, digits or space (' ').

判斷Str是否由字母、數字或空格組成。

static boolean

isAlphaSpace(String str) 
          Checks if the String contains only unicode letters and space (' ').

判斷Str是否由字母和空格組成。

static boolean

isAsciiPrintable(String str) 
          Checks if the string contains only ASCII printable characters.

判斷str是否由ASCII字符組成。

static boolean

isBlank(String str) 
          Checks if a String is whitespace, empty ("") or null.

判斷str是否是空格、空字符串或null。

static boolean

isEmpty(String str) 
          Checks if a String is empty ("") or null.

判斷str是否是空字符串或null。

static boolean

isNotBlank(String str) 
          Checks if a String is not empty (""), not null and not whitespace only.

判斷str是否不爲空且長度不爲0且不由空白符(whitespace)構成,
等於!isBlank(String str)

static boolean

isNotEmpty(String str) 
          Checks if a String is not empty ("") and not null.

判斷某字符串是否非空,等於!isEmpty(String str)

static boolean

isNumeric(String str) 
          Checks if the String contains only unicode digits.

判斷字符串str是否有數字組成。

static boolean

isNumericSpace(String str) 
          Checks if the String contains only unicode digits or space (' ').

判斷字符串str是否有數字或空字符組成。

static boolean

isWhitespace(String str) 
          Checks if the String contains only whitespace.

判斷字符串str是否是空格

static String

join(Collection collection, char separator) 
          Joins the elements of the provided Collection into a single String containing the provided elements.

把collection中的元素通過分隔符separator連接成一個字符串返回。

static String

join(Collection collection, String separator) 
          Joins the elements of the provided Collection into a single String containing the provided elements.

把collection中的元素通過分隔字符串separator連接成一個字符串返回。

static String

join(Iterator iterator, char separator) 
          Joins the elements of the provided Iterator into a single String containing the provided elements.

把iterator中的元素通過分隔字符separator連接成一個字符串返回。

static String

join(Iterator iterator, String separator) 
          Joins the elements of the provided Iterator into a single String containing the provided elements.

把iterator中的元素通過分隔字符串separator連接成一個字符串返回。

static String

join(Object[] array) 
          Joins the elements of the provided array into a single String containing the provided list of elements.

把數組array中的元素連接成一個字符串返回

static String

join(Object[] array, char separator) 
          Joins the elements of the provided array into a single String containing the provided list of elements.

把數組array中的元素通過分隔符separator連接成一個字符串返回。

static String

join(Object[] array, char separator, int startIndex, int endIndex) 
          Joins the elements of the provided array into a single String containing the provided list of elements.

把數組array中的元素通過分隔符separator連接成一個字符串返回,連接的開始位置爲startIndex,結束位置爲endIndex。

static String

join(Object[] array, String separator) 
          Joins the elements of the provided array into a single String containing the provided list of elements.

把數組array中的元素通過分隔字符串separator連接成一個字符串返回。

static String

join(Object[] array, String separator, int startIndex, int endIndex) 
          Joins the elements of the provided array into a single String containing the provided list of elements.

把數組array中的元素通過分隔字符串separator連接成一個字符串返回,連接的開始位置爲startIndex,結束位置爲endIndex。

static int

lastIndexOf(String str, char searchChar) 
          Finds the last index within a String, handling null.

返回字符searchChar在字符串str中最後一次出現的位置。
如果searchChar沒有在str中出現則返回-1,
如果str爲null或"",則也返回-1

static int

lastIndexOf(String str, char searchChar, int startPos) 
          Finds the last index within a String from a start position, handling null.

返回字符串searchStrr從startPos開始在字符串str中最後一次出現的位置。
如果從startPos開始searchStrr沒有在str中出現則返回-1,
如果str爲null或"",則也返回-1

static int

lastIndexOf(String str, String searchStr) 
          Finds the last index within a String, handling null.

返回字符串searchStr在字符串str中最後一次出現的位置。
如果str爲null或searchStr爲null則返回-1,
如果searchStr爲"",且str爲不爲null,則返回0,
如果searchStr不在str中,則返回-1

static int

lastIndexOf(String str, String searchStr, int startPos) 
          Finds the first index within a String, handling null.

返回字符串searchStrr從startPos開始在字符串str中最後一次出現的位置。
如果從startPos開始searchStrr沒有在str中出現則返回-1,
如果str爲null或"",則也返回-1

static int

lastIndexOfAny(String str, String[] searchStrs) 
          Find the latest index of any of a set of potential substrings.

找出字符數組searchStrs中的字符串最後一次出現在字符串str中的位置。 
如果字符串數組searchStrs中的字符都不在字符串str中,則返回-1 
如果searchStrs或str爲null或爲"",則返回-1 

static String

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

得到字符串str從左邊數len長度的子串。 
如果str爲null或爲"",則返回它本身 
如果len小於0,則返回""

static String

leftPad(String str, int size) 
          Left pad a String with spaces (' ').

如果字符串長度小於size,則在左邊補空格使其長度等於size,然後返回 
如果字符串長度大於等於size,則返回它本身

如果str爲null,則返回null

static String

leftPad(String str, int size, char padChar) 
          Left pad a String with a specified character.

如果字符串長度小於size,則在左邊補字符padChar使其長度等於size,然後返回 
如果字符串長度大於等於size,則返回它本身

如果str爲null,則返回null

static String

leftPad(String str, int size, String padStr) 
          Left pad a String with a specified String.

如果字符串長度小於size,則在左邊補字符串padStr使其長度等於size,然後返回 
如果字符串長度大於等於size,則返回它本身

如果str爲null,則返回null

static String

lowerCase(String str) 
          Converts a String to lower case as per String.toLowerCase().

字符串str轉換爲小寫。

static String

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

得到字符串str從pos開始len長度的子串。 
如果str爲null或爲"",則返回它本身 
如果len小於0或pos大於srt的長度,則返回"" 
如果pos小於0,則pos設爲0

static int

ordinalIndexOf(String str, String searchStr, int ordinal) 
          Finds the n-th index within a String, handling null.

返回字符串searchStr在字符串str中第ordinal次出現的位置。 
如果str=null或searchStr=null或ordinal<=0則返回-1

static String

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

用字符串overlay覆蓋字符串str從start到end之間的串。 
如果str爲null,則返回null 
如果start或end小於0,則設爲0 
如果start大於end,則兩者交換 
如果start或end大於str的長度,則認爲等於str的長度

static String

overlayString(String text, String overlay, int start, int end) 
          Deprecated. Use better named overlay(String, String, int, int) instead. Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

prechomp(String str, String sep) 
          Deprecated. Use substringAfter(String,String) instead. Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

remove(String str, char remove) 
          Removes all occurances of a character from within the source string.

去掉字符串str中所有包含字符remove的部分,然後返回

static String

remove(String str, String remove) 
          Removes all occurances of a substring from within the source string.

去掉字符串str中所有包含字符串remove的部分,然後返回

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.

如果字符串str是以字符串remove結尾,則去掉這個結尾,然後返回,否則返回原來的串。

static String

removeStart(String str, String remove) 
          Removes a substring only if it is at the begining of a source string, otherwise returns the source string.

如果字符串str是以字符串remove開始,則去掉這個開始,然後返回,否則返回原來的串。

static String

repeat(String str, int repeat) 
          Repeat a String repeat times to form a new String.

重複字符串str repeat次,組合成一個新串返回。 
如果字符串str爲null或"",則返回它本身 
如果repeat小於0,則返回""

static String

replace(String text, String repl, String with) 
          Replaces all occurrences of a String within another String.

在字符串text中用字符串with代替字符串repl,替換所有。

static String

replace(String text, String repl, String with, int max) 
          Replaces a String with another String inside a larger String, for the first max values of the search String.

在字符串text中用字符串with代替字符串repl,max爲最大替換次數。 
如果max小於0,則替換所有。

static String

replaceChars(String str, char searchChar, char replaceChar) 
          Replaces all occurrences of a character in a String with another.

在字符串str中用字符replaceChar代替所有字符searchChar,如果字符串爲null或"",則返回它本身。

static String

replaceChars(String str, String searchChars, String replaceChars) 
          Replaces multiple characters in a String in one Go.

用字符串replaceChars替換字符串str中的字符串searchChars。 
replaceChars的長度應該和searchChars的長度相等, 
如果replaceChars的長度大於searchChars的長度,超過長度的字符將被忽略, 
如果replaceChars的長度小於searchChars的長度,超過長度的字符將被刪除。

static String

replaceOnce(String text, String repl, String with) 
          Replaces a String with another String inside a larger String, once.

在字符串text中用字符串with代替repl,僅一次。

static String

reverse(String str) 
          Reverses a String as per StringBuffer.reverse().

以字符(單個詞)爲單位的反轉。

static String

reverseDelimited(String str, char separatorChar) 
          Reverses a String that is delimited by a specific character.

字符串str單詞反向排序,以separatorChar爲界限。

static String

reverseDelimitedString(String str, String separatorChars) 
          Deprecated. Use reverseDelimited(String, char) instead. This method is broken as the join doesn't know which char to use. Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

right(String str, int len) 
          Gets the rightmost len characters of a String.

得到字符串str從右邊數len長度的子串。 
如果str爲null或爲"",則返回它本身 
如果len小於0,則返回""

static String

rightPad(String str, int size) 
          Right pad a String with spaces (' ').

如果str爲null,則返回null 
如果字符串長度小於size,則在右邊補空格使其長度等於size,然後返回 
如果字符串長度大於等於size,則返回它本身

static String

rightPad(String str, int size, char padChar) 
          Right pad a String with a specified character.

如果str爲null,則返回null 
如果字符串長度小於size,則在右邊補字符padChar使其長度等於size,然後返回 
如果字符串長度大於等於size,則返回它本身。

static String

rightPad(String str, int size, String padStr) 
          Right pad a String with a specified String.

如果字符串長度小於size,則在右邊補字符串padChar使其長度等於size,然後返回 
如果字符串長度大於等於size,則返回它本身。

static String[]

split(String str) 
          Splits the provided text into an array, using whitespace as the separator.

把字符串拆分成一個字符串數組,用空白符(whitespace)作爲分隔符。 
如果字符串爲null,返回null 
如果字符串爲"",返回空數組{}

static String[]

split(String str, char separatorChar) 
          Splits the provided text into an array, separator specified.

把字符串拆分成一個字符串數組,用指定的字符separatorChar作爲分隔符。 
如果字符串爲null,返回null 
如果字符串爲"",返回空數組{}

static String[]

split(String str, String separatorChars) 
          Splits the provided text into an array, separators specified.

把字符串拆分成一個字符串數組,用指定的字符串separatorChars作爲分隔符。 
如果字符串str爲null,返回null 
如果字符串str爲"",返回空數組{} 
如果separatorChars爲null,則默認爲空白符

static String[]

split(String str, String separatorChars, int max) 
          Splits the provided text into an array with a maximum length, separators specified.

把字符串拆分成一個字符串數組,用指定的字符串separatorChars作爲分隔符, 
數組的最大長度爲max。 
如果字符串str爲null,返回null 
如果字符串str爲"",返回空數組{} 
如果separatorChars爲null,則默認爲空白符 
如果max小於等於0,認爲是沒有限制

static String[]

splitByWholeSeparator(String str, String separator) 
          Splits the provided text into an array, separator string specified.

split(String str, String separatorChars),暫時沒有發現區別

static String[]

splitByWholeSeparator(String str, String separator, int max) 
          Splits the provided text into an array, separator string specified.

split(String str, String separatorChars, int max),暫時沒有發現區別。

static String[]

splitPreserveAllTokens(String str) 
          Splits the provided text into an array, using whitespace as the separator, preserving all tokens, including empty tokens created by adjacent separators.

把字符串str拆分成一個數組,用空白符(whitespace)作爲分隔符,保留所有的標識, 
包括相鄰分隔符產生的空的標識。它可作爲StringTokenizer的一個替代。

static String[]

splitPreserveAllTokens(String str, char separatorChar) 
          Splits the provided text into an array, separator specified, preserving all tokens, including empty tokens created by adjacent separators.

把字符串str拆分成一個數組,用字符separatorChar作爲分隔符,保留所有的標識, 
包括相鄰分隔符產生的空的標識。

static String[]

splitPreserveAllTokens(String str, String separatorChars) 
          Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

把字符串str拆分成一個數組,用字符串separatorChars作爲分隔符,保留所有的標識, 
包括相鄰分隔符產生的空的標識。

static String[]

splitPreserveAllTokens(String str, String separatorChars, int max) 
          Splits the provided text into an array with a maximum length, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

把字符串str拆分成一個數組,用字符串separatorChars作爲分隔符,保留所有的標識, 
包括相鄰分隔符產生的空的標識。數組的最大長度爲max。如果max爲0或負數,則認爲沒有限制

static String

strip(String str) 
          Strips whitespace from the start and end of a String.

去掉字符串兩端的空白符(whitespace),如果輸入爲null則返回null

static String

strip(String str, String stripChars) 
          Strips any of a set of characters from the start and end of a String.

去掉str兩端的在stripChars中的字符。如果str爲null或等於"",則返回它本身; 如果stripChars爲null或"",則返回strip(String str)。

static String[]

stripAll(String[] strs) 
          Strips whitespace from the start and end of every String in an array.

對字符串數組中的每個字符串進行strip(String str),然後返回。 如果strs爲null或strs長度爲0,則返回strs本身

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(String str, String stripChars),然後返回。 如果strs爲null或strs長度爲0,則返回strs本身

static String

stripEnd(String str, String stripChars) 
          Strips any of a set of characters from the end of a String.

去掉str末端的在stripChars中的字符。如果str爲null或等於"",則返回它本身; 如果stripChars爲null或"",則返回strip(String str)。

static String

stripStart(String str, String stripChars) 
          Strips any of a set of characters from the start of a String.

去掉str前端的在stripChars中的字符。如果str爲null或等於"",則返回它本身; 如果stripChars爲null或"",則返回strip(String str)。

static String

stripToEmpty(String str) 
          Strips whitespace from the start and end of a String returning an empty String if null input.

去掉字符串兩端的空白符(whitespace), 如果變爲null或"",則返回""

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.

去掉字符串兩端的空白符(whitespace), 如果變爲null或"",則返回null

static String

substring(String str, int start) 
          Gets a substring from the specified String avoiding exceptions.

得到字符串str的子串。 如果start小於0,位置是從後往前數的第|start|個 如果str爲null或"",則返回它本身

static String

substring(String str, int start, int end) 
          Gets a substring from the specified String avoiding exceptions.

得到字符串str的子串。 如果start小於0,位置是從後往前數的第|start|個, 如果end小於0,位置是從後往前數的第|end|個, 如果str爲null或"",則返回它本身

static String

substringAfter(String str, String separator) 
          Gets the substring after the first occurrence of a separator.

得到字符串str的在字符串separator出現後的字符串,且separator不包括在內。 
如果str爲null或爲"",則返回它本身 
如果separator爲null,則返回""

static String

substringAfterLast(String str, String separator) 
          Gets the substring after the last occurrence of a separator.

得到字符串str的在字符串separator最後一次出現後的字符串,且separator不包括在內。 
如果str爲null或爲"",則返回它本身 
如果separator爲null,則返回""

static String

substringBefore(String str, String separator) 
          Gets the substring before the first occurrence of a separator.

得到字符串str的在字符串separator出現前的字串,且separator不包括在內。 
如果str爲null或爲"",則返回它本身 
如果separator爲null,則返回str本身

static String

substringBeforeLast(String str, String separator) 
          Gets the substring before the last occurrence of a separator.

得到字符串str的在字符串separator最後一次出現前的字串,且separator不包括在內。 
如果str爲null或爲"",則返回它本身 
如果separator爲null,則返回str本身

static String

substringBetween(String str, String tag) 
          Gets the String that is nested in between two instances of the same String.

得到str中的在兩個字符串tag中間的字符串,即str中的tag所夾的串。 
如果str爲null或tag爲null,返回null

static String

substringBetween(String str, String open, String close) 
          Gets the String that is nested in between two Strings.

得到str中的在兩個字符串open和close中間的字符串,即open和close所夾的串,只返回第一個匹配的結果。 
如果str爲null或open爲null或close爲null,返回null

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.

得到str中的在兩個字符串open和close中間的字符串,即open和close所夾的串, 
把所有符合的結果放在數組中返回。

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.

去掉字符串兩端的控制符(control characters, char <= 32) 
如果輸入爲null則返回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.

去掉字符串兩端的控制符(control characters, char <= 32) 如果變爲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.

去掉字符串兩端的控制符(control characters, char <= 32) 如果變爲null或"",則返回null

static String

uncapitalise(String str) 
          Deprecated. Use the standardly named uncapitalize(String). Method will be removed in Commons Lang 3.0.

過時了.Commons Lang 3.0已經沒有此方法了

static String

uncapitalize(String str) 
          Uncapitalizes a String changing the first letter to title case as per Character.toLowerCase(char).

第一個字符小寫。

static String

upperCase(String str) 
          Converts a String to upper case as per String.toUpperCase().

字符串變爲大寫。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章