日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

commons-lang3工具类学习(三)

發布時間:2024/2/28 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 commons-lang3工具类学习(三) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

六、ObjectUtils

Object工具類

allNotNull(Object... values)?檢查所有元素是否為空,返回一個boolean

如果有一個元素為空返回false,所有元素不為空或元素為empty返回trueObjectUtils.allNotNull(*) = true ObjectUtils.allNotNull(*, *) = true ObjectUtils.allNotNull(null) = false ObjectUtils.allNotNull(null, null) = false ObjectUtils.allNotNull(null, *) = false ObjectUtils.allNotNull(*, null) = false ObjectUtils.allNotNull(*, *, null, *) = false

anyNotNull(Object... values)?檢查元素是否為空,返回一個boolean

如果有一個元素不為空返回trueObjectUtils.anyNotNull(*) = true ObjectUtils.anyNotNull(*, null) = true ObjectUtils.anyNotNull(null, *) = true ObjectUtils.anyNotNull(null, null, *, *) = true ObjectUtils.anyNotNull(null) = false ObjectUtils.anyNotNull(null, null) = false

clone(T obj)?拷貝一個對象并返回

compare(T c1, T c2)?比較兩個對象,返回一個int值

defaultIfNull(T object, T defaultValue)?如果對象為空返回一個默認值

firstNonNull(T... values)?返回數組中第一個不為空的值

notEqual(Object object1, Object object2)?判斷兩個對象不相等,返回一個boolean

七、RandomUtils

隨機工具類

nextBoolean()?返回一個隨機boolean值

nextBytes(int count)?返回一個指定大小的隨機byte數組

nextDouble()?返回一個隨機double值

nextDouble(double startInclusive, double endInclusive)?返回一個指定范圍的隨機double值

nextFloat()?返回一個隨機float值

nextFloat(float startInclusive, float endInclusive)?返回一個指定范圍的隨機float值

nextInt()?返回一個隨機int值

nextInt(int startInclusive, int endExclusive)?返回一個指定范圍的隨機int值

nextLong()?返回一個隨機long值

nextLong(long startInclusive, long endExclusive)?返回一個指定范圍的隨機long值

八、SystemUtils

操作系統工具類

FILE_ENCODING?返回系統編碼

IS_JAVA_1_1、...、IS_JAVA_1_8、IS_JAVA_10、IS_JAVA_9?判斷java版本,返回一個boolean

IS_OS_LINUX?判斷系統是否是linux,返回一個boolean

IS_OS_MAC?判斷系統是否是mac,返回一個boolean

IS_OS_WINDOWS、IS_OS_WINDOWS_10、 IS_OS_WINDOWS_2000、IS_OS_WINDOWS_2003、IS_OS_WINDOWS_2008、IS_OS_WINDOWS_7、 IS_OS_WINDOWS_8、 IS_OS_WINDOWS_95、 IS_OS_WINDOWS_98、 IS_OS_WINDOWS_XP?判斷系統是否是windows,返回一個boolean

JAVA_CLASS_PATH?返回系統CLASS_PATH值

JAVA_CLASS_VERSION?返回系統java版本

JAVA_HOME?返回系統java home

JAVA_RUNTIME_VERSION?返回java運行版本

JAVA_VERSION?返回java版本

OS_NAME?返回系統名

OS_VERSION?返回系統版本

USER_COUNTRY?返回用戶國家編號

USER_DIR?返回項目文件夾

USER_HOME?返回系統用戶主文件夾

USER_LANGUAGE?返回系統用戶語言

USER_NAME?返回系統用戶名

九、StringUtils

字符串工具類

abbreviate(String str, int maxWidth)?返回一個指定長度加省略號的字符串,maxWidth必須大于3

StringUtils.abbreviate(null, *) = null StringUtils.abbreviate("", 4) = "" StringUtils.abbreviate("abcdefg", 6) = "abc..." StringUtils.abbreviate("abcdefg", 7) = "abcdefg" StringUtils.abbreviate("abcdefg", 8) = "abcdefg" StringUtils.abbreviate("abcdefg", 4) = "a..." StringUtils.abbreviate("abcdefg", 3) = IllegalArgumentException

abbreviate(String str, int offset, int maxWidth)?返回一個指定長度加省略號的字符串,maxWidth必須大于3

abbreviate(String str, String abbrevMarker, int maxWidth)?返回一個自定義省略號的指定長度字符串,maxWidth必須大于3

StringUtils.abbreviate(null, "...", *) = null StringUtils.abbreviate("abcdefg", null, *) = "abcdefg" StringUtils.abbreviate("", "...", 4) = "" StringUtils.abbreviate("abcdefg", ".", 5) = "abcd." StringUtils.abbreviate("abcdefg", ".", 7) = "abcdefg" StringUtils.abbreviate("abcdefg", ".", 8) = "abcdefg" StringUtils.abbreviate("abcdefg", "..", 4) = "ab.." StringUtils.abbreviate("abcdefg", "..", 3) = "a.." StringUtils.abbreviate("abcdefg", "..", 2) = IllegalArgumentException StringUtils.abbreviate("abcdefg", "...", 3) = IllegalArgumentException

abbreviateMiddle(String str, String abbrevMarker, int maxWidth)?將字符串縮短到指定長度(length),字符串的中間部分用替換字符串(middle)顯示

StringUtils.abbreviateMiddle("abc", null, 0) = "abc" StringUtils.abbreviateMiddle("abc", ".", 0) = "abc" StringUtils.abbreviateMiddle("abc", ".", 3) = "abc" StringUtils.abbreviateMiddle("abcdef", ".", 4) = "ab.f"

appendIfMissing(String str, CharSequence suffix, CharSequence... suffixes)?如果str不是以任何suffixes結尾,將字符串suffix拼接到字符串str后面

StringUtils.appendIfMissing(null, null) = null StringUtils.appendIfMissing("abc", null) = "abc" StringUtils.appendIfMissing("", "xyz") = "xyz" StringUtils.appendIfMissing("abc", "xyz") = "abcxyz" StringUtils.appendIfMissing("abcxyz", "xyz") = "abcxyz" StringUtils.appendIfMissing("abcXYZ", "xyz") = "abcXYZxyz"

appendIfMissingIgnoreCase(String str, CharSequence suffix, CharSequence... suffixes)?同上 不區分大小寫

capitalize(String str)?將字符串第一個字符大寫并返回

center(String str, int size)?用空格字符填充使字符串str位于長度為size的大字符串中間

StringUtils.center(null, *) = null StringUtils.center("", 4) = " " StringUtils.center("ab", -1) = "ab" StringUtils.center("ab", 4) = " ab " StringUtils.center("abcd", 2) = "abcd" StringUtils.center("a", 4) = " a "

center(String str, int size, char padChar)?用指定字符填充使字符串str位于長度為size的大字符串中間

chomp(String str)?刪除字符串末尾的一個換行符,返回一個新的字符串(換行符"n", "r", or "rn")

StringUtils.chomp(null) = null StringUtils.chomp("") = "" StringUtils.chomp("abc \r") = "abc " StringUtils.chomp("abc\n") = "abc" StringUtils.chomp("abc\r\n") = "abc" StringUtils.chomp("abc\r\n\r\n") = "abc\r\n" StringUtils.chomp("abc\n\r") = "abc\n" StringUtils.chomp("abc\n\rabc") = "abc\n\rabc" StringUtils.chomp("\r") = "" StringUtils.chomp("\n") = "" StringUtils.chomp("\r\n") = ""

chop(String str)?刪除字符串末尾的一個字符,返回一個新的字符串

StringUtils.chop(null) = null StringUtils.chop("") = "" StringUtils.chop("abc \r") = "abc " StringUtils.chop("abc\n") = "abc" StringUtils.chop("abc\r\n") = "abc" StringUtils.chop("abc") = "ab" StringUtils.chop("abc\nabc") = "abc\nab" StringUtils.chop("a") = "" StringUtils.chop("\r") = "" StringUtils.chop("\n") = "" StringUtils.chop("\r\n") = ""

compare(String str1, String str2)?比較兩個字符串,返回一個int值

str1等于str2(或都為空)返回0 str1小于str2返回小于0 str1大于str2返回大于0StringUtils.compare(null, null) = 0 StringUtils.compare(null , "a") < 0 StringUtils.compare("a", null) > 0 StringUtils.compare("abc", "abc") = 0 StringUtils.compare("a", "b") < 0 StringUtils.compare("b", "a") > 0 StringUtils.compare("a", "B") > 0 StringUtils.compare("ab", "abc") < 0

contains(CharSequence seq, CharSequence searchSeq)?檢查字符串中是否包含指定字符,返回boolean

StringUtils.contains(null, *) = false StringUtils.contains(*, null) = false StringUtils.contains("", "") = true StringUtils.contains("abc", "") = true StringUtils.contains("abc", "a") = true StringUtils.contains("abc", "z") = false

containsAny(CharSequence cs, CharSequence... searchCharSequences)?檢查字符串中是否包含任一字符,返回boolean

StringUtils.containsAny(null, *) = false StringUtils.containsAny("", *) = false StringUtils.containsAny(*, null) = false StringUtils.containsAny(*, []) = false StringUtils.containsAny("abcd", "ab", null) = true StringUtils.containsAny("abcd", "ab", "cd") = true StringUtils.containsAny("abc", "d", "abc") = true

containsNone(CharSequence cs, String invalidChars)?檢查字符串不包含指定字符,返回boolean

StringUtils.containsNone(null, *) = true StringUtils.containsNone(*, null) = true StringUtils.containsNone("", *) = true StringUtils.containsNone("ab", "") = true StringUtils.containsNone("abab", "xyz") = true StringUtils.containsNone("ab1", "xyz") = true StringUtils.containsNone("abz", "xyz") = false

containsOnly(CharSequence cs, String validChars)?檢查字符串只包含特定的字符,返回boolean

StringUtils.containsOnly(null, *) = false StringUtils.containsOnly(*, null) = false StringUtils.containsOnly("", *) = true StringUtils.containsOnly("ab", "") = false StringUtils.containsOnly("abab", "abc") = true StringUtils.containsOnly("ab1", "abc") = false StringUtils.containsOnly("abz", "abc") = false

containsWhitespace(CharSequence seq)?檢查字符串中是否包含空格字符,返回boolean

countMatches(CharSequence str, CharSequence sub)?檢查字符串中出現指定字符的次數,返回一個int值

StringUtils.countMatches(null, *) = 0 StringUtils.countMatches("", *) = 0 StringUtils.countMatches("abba", null) = 0 StringUtils.countMatches("abba", "") = 0 StringUtils.countMatches("abba", "a") = 2 StringUtils.countMatches("abba", "ab") = 1 StringUtils.countMatches("abba", "xxx") = 0

defaultIfBlank(T str, T defaultStr)?如果字符串為null、空(""),或全是空格,將返回指定字符串,否則返回原值

StringUtils.defaultIfBlank(null, "NULL") = "NULL" StringUtils.defaultIfBlank("", "NULL") = "NULL" StringUtils.defaultIfBlank(" ", "NULL") = "NULL" StringUtils.defaultIfBlank("bat", "NULL") = "bat" StringUtils.defaultIfBlank("", null) = null

defaultIfEmpty(T str, T defaultStr)?如果字符串為null、空(""),將返回指定字符串,否則返回原值

StringUtils.defaultIfEmpty(null, "NULL") = "NULL" StringUtils.defaultIfEmpty("", "NULL") = "NULL" StringUtils.defaultIfEmpty(" ", "NULL") = " " StringUtils.defaultIfEmpty("bat", "NULL") = "bat" StringUtils.defaultIfEmpty("", null) = null

defaultString(String str)?如果字符串為null,將返回空的字符串(""),否則返回原值

StringUtils.defaultString(null) = "" StringUtils.defaultString("") = "" StringUtils.defaultString("bat") = "bat"

defaultString(String str, String defaultStr)?如果字符串為null,將返回指定字符,否則返回原值

StringUtils.defaultString(null, "NULL") = "NULL" StringUtils.defaultString("", "NULL") = "" StringUtils.defaultString("bat", "NULL") = "bat"

deleteWhitespace(String str)?刪除字符串中的空格字符,并返回新的字符串

StringUtils.deleteWhitespace(null) = null StringUtils.deleteWhitespace("") = "" StringUtils.deleteWhitespace("abc") = "abc" StringUtils.deleteWhitespace(" ab c ") = "abc"

difference(String str1, String str2)?比較兩個字符串差異,并返回差異的字符,返回第二個字符串的剩余部分,這意味著“ABC”和“AB”之間的區別是空字符串而不是“C”。

StringUtils.difference(null, null) = null StringUtils.difference("", "") = "" StringUtils.difference("", "abc") = "abc" StringUtils.difference("abc", "") = "" StringUtils.difference("abc", "abc") = "" StringUtils.difference("abc", "ab") = "" StringUtils.difference("ab", "abxyz") = "xyz" StringUtils.difference("abcde", "abxyz") = "xyz" StringUtils.difference("abcde", "xyz") = "xyz"

endsWith(CharSequence str, CharSequence suffix)?檢查字符串是否以指定字符結尾,返回一個boolean

StringUtils.endsWith(null, null) = true StringUtils.endsWith(null, "def") = false StringUtils.endsWith("abcdef", null) = false StringUtils.endsWith("abcdef", "def") = true StringUtils.endsWith("ABCDEF", "def") = false StringUtils.endsWith("ABCDEF", "cde") = false StringUtils.endsWith("ABCDEF", "") = true

endsWithAny(CharSequence sequence, CharSequence... searchStrings)?檢查字符串是否以指定字符數組結尾,返回一個boolean

StringUtils.endsWithAny(null, null) = false StringUtils.endsWithAny(null, new String[] {"abc"}) = false StringUtils.endsWithAny("abcxyz", null) = false StringUtils.endsWithAny("abcxyz", new String[] {""}) = true StringUtils.endsWithAny("abcxyz", new String[] {"xyz"}) = true StringUtils.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true StringUtils.endsWithAny("abcXYZ", "def", "XYZ") = true StringUtils.endsWithAny("abcXYZ", "def", "xyz") = false

endsWithIgnoreCase(CharSequence str, CharSequence suffix)?檢查字符串是否以指定字符(不區分大小寫)結尾,返回一個boolean

StringUtils.endsWithIgnoreCase(null, null) = true StringUtils.endsWithIgnoreCase(null, "def") = false StringUtils.endsWithIgnoreCase("abcdef", null) = false StringUtils.endsWithIgnoreCase("abcdef", "def") = true StringUtils.endsWithIgnoreCase("ABCDEF", "def") = true StringUtils.endsWithIgnoreCase("ABCDEF", "cde") = false

equals(CharSequence cs1, CharSequence cs2)?比較兩個字符串是否相等,返回一個boolean

StringUtils.equals(null, null) = true StringUtils.equals(null, "abc") = false StringUtils.equals("abc", null) = false StringUtils.equals("abc", "abc") = true StringUtils.equals("abc", "ABC") = false

equalsAnyIgnoreCase(CharSequence string, CharSequence... searchStrings) 比較兩個字符串是否相等(不區分大小寫),返回一個boolean

StringUtils.equalsIgnoreCase(null, null) = true StringUtils.equalsIgnoreCase(null, "abc") = false StringUtils.equalsIgnoreCase("abc", null) = false StringUtils.equalsIgnoreCase("abc", "abc") = true StringUtils.equalsIgnoreCase("abc", "ABC") = true

equalsAny(CharSequence string, CharSequence... searchStrings)?比較字符串是否與指定字符串數組中某一值相等,返回一個boolean

StringUtils.equalsAny(null, (CharSequence[]) null) = false StringUtils.equalsAny(null, null, null) = true StringUtils.equalsAny(null, "abc", "def") = false StringUtils.equalsAny("abc", null, "def") = false StringUtils.equalsAny("abc", "abc", "def") = true StringUtils.equalsAny("abc", "ABC", "DEF") = false

equalsAnyIgnoreCase(CharSequence string, CharSequence... searchStrings)?比較字符串是否與指定字符串數組中某一值相等(不區分大小寫),返回一個boolean

StringUtils.equalsAnyIgnoreCase(null, (CharSequence[]) null) = false StringUtils.equalsAnyIgnoreCase(null, null, null) = true StringUtils.equalsAnyIgnoreCase(null, "abc", "def") = false StringUtils.equalsAnyIgnoreCase("abc", null, "def") = false StringUtils.equalsAnyIgnoreCase("abc", "abc", "def") = true StringUtils.equalsAnyIgnoreCase("abc", "ABC", "DEF") = true

getCommonPrefix(String... strs)?獲取字符串數組元素公共字符,返回string

StringUtils.getCommonPrefix(null) = "" StringUtils.getCommonPrefix(new String[] {}) = "" StringUtils.getCommonPrefix(new String[] {"abc"}) = "abc" StringUtils.getCommonPrefix(new String[] {null, null}) = "" StringUtils.getCommonPrefix(new String[] {"", ""}) = "" StringUtils.getCommonPrefix(new String[] {"", null}) = "" StringUtils.getCommonPrefix(new String[] {"abc", null, null}) = "" StringUtils.getCommonPrefix(new String[] {null, null, "abc"}) = "" StringUtils.getCommonPrefix(new String[] {"", "abc"}) = "" StringUtils.getCommonPrefix(new String[] {"abc", ""}) = "" StringUtils.getCommonPrefix(new String[] {"abc", "abc"}) = "abc" StringUtils.getCommonPrefix(new String[] {"abc", "a"}) = "a" StringUtils.getCommonPrefix(new String[] {"ab", "abxyz"}) = "ab" StringUtils.getCommonPrefix(new String[] {"abcde", "abxyz"}) = "ab" StringUtils.getCommonPrefix(new String[] {"abcde", "xyz"}) = "" StringUtils.getCommonPrefix(new String[] {"xyz", "abcde"}) = "" StringUtils.getCommonPrefix(new String[] {"i am a machine", "i am a robot"}) = "i am a "

indexOf(CharSequence seq, CharSequence searchSeq)?檢查指定字符在字符串中出現的位置,返回一個int值

StringUtils.indexOf(null, *) = -1 StringUtils.indexOf(*, null) = -1 StringUtils.indexOf("", "") = 0 StringUtils.indexOf("", *) = -1 (except when * = "") StringUtils.indexOf("aabaabaa", "a") = 0 StringUtils.indexOf("aabaabaa", "b") = 2 StringUtils.indexOf("aabaabaa", "ab") = 1 StringUtils.indexOf("aabaabaa", "") = 0

indexOfIgnoreCase(CharSequence seq, CharSequence searchSeq)?檢查指定字符在字符串中出現的位置(不區分大小寫),返回一個int值

isAllBlank(CharSequence... css)?檢查數組所有字符是否為null、empty、或全是空格字符,返回一個boolean

StringUtils.isAllBlank(null) = true StringUtils.isAllBlank(null, "foo") = false StringUtils.isAllBlank(null, null) = true StringUtils.isAllBlank("", "bar") = false StringUtils.isAllBlank("bob", "") = false StringUtils.isAllBlank(" bob ", null) = false StringUtils.isAllBlank(" ", "bar") = false StringUtils.isAllBlank("foo", "bar") = false StringUtils.isAllBlank(new String[] {}) = true

isAllEmpty(CharSequence... css)?檢查數組所有字符是否為null、empty,返回一個boolean

StringUtils.isAllEmpty(null) = true StringUtils.isAllEmpty(null, "") = true StringUtils.isAllEmpty(new String[] {}) = true StringUtils.isAllEmpty(null, "foo") = false StringUtils.isAllEmpty("", "bar") = false StringUtils.isAllEmpty("bob", "") = false StringUtils.isAllEmpty(" bob ", null) = false StringUtils.isAllEmpty(" ", "bar") = false StringUtils.isAllEmpty("foo", "bar") = false

isAllLowerCase(CharSequence cs)?檢查字符串中所有字符是否是小寫,返回一個boolean

isAllUpperCase(CharSequence cs)?檢查字符串中所有字符是否是大寫,返回一個boolean

isAnyBlank(CharSequence... css)?檢查數組中字符串是否有一個為null、empty或全是空格字符,返回一個boolean

StringUtils.isAnyBlank(null) = true StringUtils.isAnyBlank(null, "foo") = true StringUtils.isAnyBlank(null, null) = true StringUtils.isAnyBlank("", "bar") = true StringUtils.isAnyBlank("bob", "") = true StringUtils.isAnyBlank(" bob ", null) = true StringUtils.isAnyBlank(" ", "bar") = true StringUtils.isAnyBlank(new String[] {}) = false StringUtils.isAnyBlank(new String[]{""}) = true StringUtils.isAnyBlank("foo", "bar") = false

isAnyEmpty(CharSequence... css)?檢查數組中字符串是否有一個為null、empty,返回一個boolean

StringUtils.isAnyEmpty(null) = true StringUtils.isAnyEmpty(null, "foo") = true StringUtils.isAnyEmpty("", "bar") = true StringUtils.isAnyEmpty("bob", "") = true StringUtils.isAnyEmpty(" bob ", null) = true StringUtils.isAnyEmpty(" ", "bar") = false StringUtils.isAnyEmpty("foo", "bar") = false StringUtils.isAnyEmpty(new String[]{}) = false StringUtils.isAnyEmpty(new String[]{""}) = true

isBlank(CharSequence cs)?檢查字符串是否為null、empty或空格字符,返回一個boolean

StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false

isEmpty(CharSequence cs)?檢查字符串是否為null、empty,返回一個boolean

StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false

isNotBlank(CharSequence cs)?檢查字符串是否不為null、empty或空格字符,返回一個boolean

isNotEmpty(CharSequence cs)?檢查字符串是否不為null、empty,返回一個boolean

isNumeric(CharSequence cs)?檢查字符串是否是數字,返回一個boolean

StringUtils.isNumeric(null) = false StringUtils.isNumeric("") = false StringUtils.isNumeric(" ") = false StringUtils.isNumeric("123") = true StringUtils.isNumeric("???") = true StringUtils.isNumeric("12 3") = false StringUtils.isNumeric("ab2c") = false StringUtils.isNumeric("12-3") = false StringUtils.isNumeric("12.3") = false StringUtils.isNumeric("-123") = false StringUtils.isNumeric("+123") = false

isWhitespace(CharSequence cs)?檢查字符串是否是空格字符,返回一個boolean

StringUtils.isWhitespace(null) = false StringUtils.isWhitespace("") = true StringUtils.isWhitespace(" ") = true StringUtils.isWhitespace("abc") = false StringUtils.isWhitespace("ab2c") = false StringUtils.isWhitespace("ab-c") = false

join(byte[] array, char separator)?將字節數組轉換成string,以指定字符分隔

StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join([1, 2, 3], ';') = "1;2;3" StringUtils.join([1, 2, 3], null) = "123"

char、double、float、int、long、short、object、T同理

joinWith(String separator, Object... objects)?將多個元素已指定字符分隔拼接成String

StringUtils.joinWith(",", {"a", "b"}) = "a,b" StringUtils.joinWith(",", {"a", "b",""}) = "a,b," StringUtils.joinWith(",", {"a", null, "b"}) = "a,,b" StringUtils.joinWith(null, {"a", "b"}) = "ab"

lastIndexOf(CharSequence seq, CharSequence searchSeq)?獲取指定字符在字符串中的最后一個索引位置

StringUtils.lastIndexOf(null, *) = -1 StringUtils.lastIndexOf(*, null) = -1 StringUtils.lastIndexOf("", "") = 0 StringUtils.lastIndexOf("aabaabaa", "a") = 7 StringUtils.lastIndexOf("aabaabaa", "b") = 5 StringUtils.lastIndexOf("aabaabaa", "ab") = 4 StringUtils.lastIndexOf("aabaabaa", "") = 8

left(String str, int len)?返回從左邊開始指定大小的字符串

StringUtils.left(null, *) = null StringUtils.left(*, -ve) = "" StringUtils.left("", *) = "" StringUtils.left("abc", 0) = "" StringUtils.left("abc", 2) = "ab" StringUtils.left("abc", 4) = "abc"

right(String str, int len)?同上相反

length(CharSequence cs)?獲取字符串大小,返回一個int

lowerCase(String str)?將字符串轉換為小寫,返回一個string

StringUtils.lowerCase(null) = null StringUtils.lowerCase("") = "" StringUtils.lowerCase("aBc") = "abc"

upperCase(String str)?同上相反

mid(String str, int pos, int len)?獲取字符串指定位置區間的字符,返回一個string

StringUtils.mid(null, *, *) = null StringUtils.mid(*, *, -ve) = "" StringUtils.mid("", 0, *) = "" StringUtils.mid("abc", 0, 2) = "ab" StringUtils.mid("abc", 0, 4) = "abc" StringUtils.mid("abc", 2, 4) = "c" StringUtils.mid("abc", 4, 2) = "" StringUtils.mid("abc", -2, 2) = "ab"

overlay(String str, String overlay, int start, int end)?在字符串位置區間插入指定字符,返回一個string

StringUtils.overlay(null, *, *, *) = null StringUtils.overlay("", "abc", 0, 0) = "abc" StringUtils.overlay("abcdef", null, 2, 4) = "abef" StringUtils.overlay("abcdef", "", 2, 4) = "abef" StringUtils.overlay("abcdef", "", 4, 2) = "abef" StringUtils.overlay("abcdef", "zzzz", 2, 4) = "abzzzzef" StringUtils.overlay("abcdef", "zzzz", 4, 2) = "abzzzzef" StringUtils.overlay("abcdef", "zzzz", -1, 4) = "zzzzef" StringUtils.overlay("abcdef", "zzzz", 2, 8) = "abzzzz" StringUtils.overlay("abcdef", "zzzz", -2, -3) = "zzzzabcdef" StringUtils.overlay("abcdef", "zzzz", 8, 10) = "abcdefzzzz"

prependIfMissing(String str, CharSequence prefix, CharSequence... prefixes)?在字符串最左邊插入指定字符,如果已存在,將不插入,返回一個string

StringUtils.prependIfMissing(null, null) = null StringUtils.prependIfMissing("abc", null) = "abc" StringUtils.prependIfMissing("", "xyz") = "xyz" StringUtils.prependIfMissing("abc", "xyz") = "xyzabc" StringUtils.prependIfMissing("xyzabc", "xyz") = "xyzabc" StringUtils.prependIfMissing("XYZabc", "xyz") = "xyzXYZabc"

prependIfMissingIgnoreCase(String str, CharSequence prefix, CharSequence... prefixes)?同上,只是不區分大小寫

remove(String str, char remove)?刪除字符串中指定字符,返回一個string

StringUtils.remove(null, *) = null StringUtils.remove("", *) = "" StringUtils.remove("queued", 'u') = "qeed" StringUtils.remove("queued", 'z') = "queued"

removeIgnoreCase(String str, String remove)?同上,只是不區分大小寫

removeAll(String text, String regex)?根據匹配規則刪除所有字符,返回一個string

StringUtils.removeAll(null, *) = null StringUtils.removeAll("any", null) = "any" StringUtils.removeAll("any", "") = "any" StringUtils.removeAll("any", ".*") = "" StringUtils.removeAll("any", ".+") = "" StringUtils.removeAll("abc", ".?") = "" StringUtils.removeAll("A<__>\n<__>B", "<.*>") = "A\nB" StringUtils.removeAll("A<__>\n<__>B", "(?s)<.*>") = "AB" StringUtils.removeAll("ABCabc123abc", "[a-z]") = "ABC123"

removeEnd(String str, String remove)?刪除字符串結尾指定字符,返回一個string

StringUtils.removeEnd(null, *) = null StringUtils.removeEnd("", *) = "" StringUtils.removeEnd(*, null) = * StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com" StringUtils.removeEnd("www.domain.com", ".com") = "www.domain" StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com" StringUtils.removeEnd("abc", "") = "abc"

removeStart(String str, String remove)?同上相反

removeEndIgnoreCase(String str, String remove)?同上,只是不區分大小寫

removeFirst(String text, String regex)?根據匹配規則刪除第一次出現的字符,返回一個string

StringUtils.removeFirst(null, *) = null StringUtils.removeFirst("any", null) = "any" StringUtils.removeFirst("any", "") = "any" StringUtils.removeFirst("any", ".*") = "" StringUtils.removeFirst("any", ".+") = "" StringUtils.removeFirst("abc", ".?") = "bc" StringUtils.removeFirst("A<__>\n<__>B", "<.*>") = "A\n<__>B" StringUtils.removeFirst("A<__>\n<__>B", "(?s)<.*>") = "AB" StringUtils.removeFirst("ABCabc123", "[a-z]") = "ABCbc123" StringUtils.removeFirst("ABCabc123abc", "[a-z]+") = "ABC123abc"

repeat(String str, int repeat)?將字符重復指定次數拼接成新的字符串,返回一個string

StringUtils.repeat(null, 2) = null StringUtils.repeat("", 0) = "" StringUtils.repeat("", 2) = "" StringUtils.repeat("a", 3) = "aaa" StringUtils.repeat("ab", 2) = "abab" StringUtils.repeat("a", -2) = ""

replace(String text, String searchString, String replacement)?用replacement替換字符串中的所有searchString,返回一個string

StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("any", null, *) = "any" StringUtils.replace("any", *, null) = "any" StringUtils.replace("any", "", *) = "any" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "b" StringUtils.replace("aba", "a", "z") = "zbz"

reverse(String str)?將字符串反轉,返回一個string

StringUtils.reverse(null) = null StringUtils.reverse("") = "" StringUtils.reverse("bat") = "tab"

reverseDelimited(String str, char separatorChar)?將字符串指定分隔符出的字符反轉

StringUtils.reverseDelimited(null, *) = nullStringUtils.reverseDelimited("", *) = ""StringUtils.reverseDelimited("a.b.c", 'x') = "a.b.c"StringUtils.reverseDelimited("a.b.c", ".") = "c.b.a"

split(String str, String separatorChars)?將字符串以指定字符分隔,返回數組

StringUtils.split(null, *) = null StringUtils.split("", *) = [] StringUtils.split("abc def", null) = ["abc", "def"] StringUtils.split("abc def", " ") = ["abc", "def"] StringUtils.split("abc def", " ") = ["abc", "def"] StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]

substring(String str, int start)?將字符串從指定位置區間截取,返回string

swapCase(String str)?將字符串大小寫互轉,返回一個string

StringUtils.swapCase(null) = null StringUtils.swapCase("") = "" StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"

toEncodedString(byte[] bytes, Charset charset)?將字符串轉為指定編碼格式,返回一個string

trim(String str)?去除字符串空格

trimToEmpty(String str)?去除字符串空格,null轉為empty,返回一個string

StringUtils.trimToEmpty(null) = "" StringUtils.trimToEmpty("") = "" StringUtils.trimToEmpty(" ") = "" StringUtils.trimToEmpty("abc") = "abc" StringUtils.trimToEmpty(" abc ") = "abc"
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的commons-lang3工具类学习(三)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 九色网站在线观看 | 日本在线播放视频 | 精品熟妇视频一区二区三区 | 黑人一区二区三区四区五区 | 国产 一二三四五六 | 一区二区三区久久精品 | 黄色精彩视频 | 欧美性视频一区二区三区 | 欧美精品久久久久a | 国产裸体永久免费无遮挡 | 亚洲天堂网址 | 99re国产精品| 欧美精品成人一区二区在线观看 | 欧美精品久久久 | 九九精品在线观看视频 | 国产小视频网站 | 成人在线国产视频 | 嫩草嫩草嫩草嫩草嫩草 | 黑人操日本女人 | 亚洲搞av | 天堂网视频 | 农民人伦一区二区三区 | 激情深爱五月 | 亚洲日本在线观看 | 成人永久免费视频 | 夜夜操综合 | 国产免费av一区二区 | 69**夜色精品国产69乱 | 国产小视频网站 | 日本特级黄色片 | 91一区二区三区在线 | 午夜精品视频在线观看 | 黄色片免费观看视频 | 日本在线色 | 天堂a√在线 | 中文字幕免费高清 | 欧美一区二区三区激情视频 | 中文字幕 欧美 日韩 | 91网站免费看| 日xxxx| 国产一区二区在线免费观看视频 | 中文字字幕一区二区三区四区五区 | 波多野结衣在线观看一区二区三区 | 69人妻精品久久无人专区 | 性欧美videossex精品 | 自拍偷拍欧美日韩 | 日韩欧美国产精品综合嫩v 国产小毛片 | 青娱网电信一区电信二区电信三区 | 69成人免费视频 | 理论片琪琪午夜电影 | 邻居少妇张开腿让我爽了在线观看 | 国产天堂一区 | 欧美黄色免费在线观看 | 亚洲国产成人va在线观看天堂 | 樱花影院最新免费观看攻略 | 女性裸体不遮胸图片 | 中文字幕第22页 | 色欲一区二区三区精品a片 在线观看黄网站 | 国产裸体网站 | 成人免费性视频 | av在线免费播放网站 | 极品色影视 | 国产草草影院 | 老司机伊人 | 亚洲视频在线观看免费 | 精品国产99久久久久久宅男i | wwwwxxxx国产 | 永久免费观看av | 超碰99在线观看 | 一级片高清 | 国产在线天堂 | 18禁裸乳无遮挡啪啪无码免费 | 亚洲午夜精品久久久久久浪潮 | 日韩高清成人 | 亚洲综合色成人 | 中国女人av | 美女久久视频 | 国产精品扒开腿做爽爽爽a片唱戏 | 日韩一区二区三区精品视频 | 欧美人成在线 | 麻豆91视频| 午夜免费体验区 | 久久99精品久久久久久水蜜桃 | 日韩视频福利 | 国产91热爆ts人妖系列 | 精品久久久久久久无码 | 亚洲av乱码久久精品蜜桃 | 麻豆国产精品777777在线 | 日本少妇ⅹxxxxx视频 | 国产高潮视频在线观看 | 久久影片 | 日韩av影视大全 | 亚洲精品国产精品乱码 | 中文字幕国产 | 少妇99 | 欧美一级视频免费 | 国产刺激对白 | 日本免费无人高清 | 99热精品久久 |