標籤:sci 反轉 commons tail 操作 style related delete mon
org.apache.commons.lang
Class StringUtils
java.lang.Object
org.apache.commons.lang.StringUtils
public class StringUtilsextends Object
Operations on String that are null safe.
- IsEmpty/IsBlank - checks if a String contains text
- Trim/Strip - removes leading and trailing whitespace
- Equals - compares two strings null-safe
- startsWith - check if a String starts with a prefix null-safe
- endsWith - check if a String ends with a suffix null-safe
- IndexOf/LastIndexOf/Contains - null-safe index-of checks
- IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut - index-of any of a set of Strings
- ContainsOnly/ContainsNone/ContainsAny - does String contains only/none/any of these characters
- Substring/Left/Right/Mid - null-safe substring extractions
- SubstringBefore/SubstringAfter/SubstringBetween - substring extraction relative to other strings
- Split/Join - splits a String into an array of substrings and vice versa
- Remove/Delete - removes part of a String
- Replace/Overlay - Searches a String and replaces one String with another
- Chomp/Chop - removes the last part of a String
- LeftPad/RightPad/Center/Repeat - pads a String
- UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize - changes the case of a String
- CountMatches - counts the number of occurrences of one String in another
- IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable - checks the characters in a String
- DefaultString - protects against a null input String
- Reverse/ReverseDelimited - reverses a String
- Abbreviate - abbreviates a string using ellipsis
- Difference - compares Strings and reports on their differences
- LevensteinDistance - the number of changes needed to change one String into another
The StringUtils class defines certain words related to String handling.
- null -
null
- empty - a zero-length string (
"")
- space - the space character (
‘ ‘, char 32)
- whitespace - the characters defined by
Character.isWhitespace(char)
- trim - the characters <= 32 as in
String.trim()
StringUtils handles null input Strings quietly. That is to say that a null input will return null. Where a boolean or int is being returned details vary by method.
A side effect of the null handling is that a NullPointerException should be considered a bug in StringUtils (except for deprecated methods).
Methods in this class give sample code to explain their operation. The symbol * is used to indicate any input including null.
翻譯:Google
org.apache.commons.lang
類StringUtils
java.lang.Object
org.apache.commons.lang.StringUtils
公用類StringUtils擴充Object
這樣做的操作String是 null安全的。
- IsEmpty / IsBlank - 檢查一個String是否包含文本
- 修剪/去除 - 去除前置和尾隨的空白
- 等於 - 比較兩個字串無效
- startsWith - 檢查一個字串是否以一個首碼為null開頭
- endsWith - 檢查一個String是否以一個尾碼為null結尾
- IndexOf / LastIndexOf / Contains - 無效索引的檢查
- IndexOfAny / LastIndexOfAny / IndexOfAnyBut / LastIndexOfAnyBut - 索引 - 任何一組字串
- ContainsOnly / ContainsNone / ContainsAny - 是String只包含/ none /任何這些字元
- 子字串/左/右/中 - 零安全子串提取
- SubstringBefore / SubstringAfter / SubstringBetween - 相對於其他字串的子字串提取
- 拆分/串連 - 將一個字串拆分為一個子字串數組,反之亦然
- 刪除/刪除 - 刪除部分字串
- 替換/覆蓋 - 搜尋一個字串並用另一個替換一個字串
- Chomp / Chop - 刪除字串的最後部分
- 左鍵盤/右鍵盤/中心/重複 - 填充字串
- UpperCase / LowerCase / SwapCase / Capitalize / Uncapitalize - 更改字串的大小寫
- CountMatches - 統計另一個字串的出現次數
- IsAlpha / IsNumeric / IsWhitespace / IsAsciiPrintable - 檢查字串中的字元
- DefaultString - 防止空輸入字串
- Reverse / ReverseDelimited - 反轉字串
- 縮寫 - 使用省略符號縮寫字串
- 差異 - 比較字串和報告差異
- LevensteinDistance - 將一個字串更改為另一個字串所需的更改次數
在StringUtils類定義與字串處理某些詞。
- 空值 -
null
- 空 - 一個零長度的字串(
"")
- 空格 - 空白字元(
‘ ‘char 32)
- 空格 - 由...定義的字元
Character.isWhitespace(char)
- 修剪 - 在<= 32的字元
String.trim()
StringUtilsnull靜靜地處理輸入字串。這就是說,一個null輸入將返回null。在哪裡boolean或int正在退貨的細節因方法而異。
處理的一個副作用null是a NullPointerException應該被認為是一個錯誤 StringUtils(除了被棄用的方法)。
這個類中的方法給出了範例程式碼來解釋它們的操作。該符號*用於指示包括的任何輸入null。
檢查字串是否為空白
isNotEmpty 將空格也作為參數,isNotBlank 則排除空格參數
isNoneEmpty 可添加多個參數將空格也作為參數 , isNoneBlank 可添加多個參數,排除空格參數
去掉字串前後的空白
Trim/Strip
比較兩個字串是否相等
Equals
檢查字串是否以null首碼為開頭
startsWith
檢查字串是否以null尾碼為結尾
檢查字串是否包含一個特定的字元
IndexOf / LastIndexOf / Contains
JAVA StringUtils工具類