通用的Java工具類,幫你快速提升編碼效率
commons-lang的jar包工具:
一,org.apache.commons.lang.StringUtils字符串工具類
1、isBlank:字符串是否為空,空白字符(ascii為0)不算空
2、isEmpty:字符串是否為空,空白字符(ascii為0)不算空
3、equals:判斷字符串內(nèi)容是否相等
4、join:數(shù)組合并為字符串,可使用分隔符
5、split:分割字符串
6、EMPTY:返回空字符串
7、trimToNull:如果trim后字符串為空,則將字符串對象轉(zhuǎn)為null
8、replace:字符串替換
9、deleteWhitespace:刪除字符串中空白
10、lowerCase:字符串中的大寫字母變小寫
11、upperCase:字符串中的小寫字母變大寫
12、remove:刪除當(dāng)前字符串的某一段
13、repeat:重復(fù)次數(shù)
14、rightPad:字符串填充
doc:https://commons.apache.org/proper/commons-lang/apidocs/index.html?org/apache/commons/lang3/StringUtils.html
apache下載:
https://commons.apache.org/proper/commons-lang/

二,org.apache.commons.collections.CollectionUtils集合工具類
1、isEmpty:判斷集合是否為空
2、select:根據(jù)給定的條件篩選出集合元素,返回原集合
3、transform:根據(jù)指定方法進(jìn)行集合元素處理
4、filter:過濾集合元素
5、collect:根據(jù)給定的條件篩選出集合元素,返回新的集合
6、isEqualCollection:判斷兩個集合的內(nèi)容是否一致
doc:https://commons.apache.org/proper/commons-collections/javadocs/api-3.2.2/org/apache/commons/collections/CollectionUtils.html
apache下載:
https://commons.apache.org/proper/commons-lang/

三,org.apache.commons.io.FileUtils文件操作工具類
1、deleteDirectory:刪除目錄
2、readFileToString:讀取文件內(nèi)容到字符串
3、deleteQueitly:刪除文件或目錄
4、copyFile:復(fù)制文件
5、writeStringToFile:將字符串內(nèi)容寫入到給定的文件內(nèi),若是文件不存在則創(chuàng)建
6、forceMkdir:強(qiáng)制創(chuàng)建目錄,目錄或上級目錄若不存在則創(chuàng)建
7、write:寫字符到目標(biāo)文件內(nèi)
8、listFiles:根據(jù)篩選條件,列出某個目錄下的各個文件
9、copyDirectory:復(fù)制文件目錄
10、forceDelete:強(qiáng)制刪除文件
doc:https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/FileUtils.html
apache下載:
https://commons.apache.org/proper/commons-lang/

四,org.apache.commons.io.IOUtils輸入輸出工具類
1、closeQuietly:關(guān)閉一個IO流Stream、Socket、Selector且不拋出異常,通常可以放在finnally中。
2、toString:將IO流Stream轉(zhuǎn)為String
3、copy:IO流Stream的復(fù)制操作
4、toByteArray:從輸入流Stream中獲取Byte數(shù)組
5、toInputStream:將字符串轉(zhuǎn)為輸入流Stream
6、readLines:輸入流Stream中讀取多行字符串
7、lineIterator:根據(jù)輸入流Stream中返回一個迭代器,根據(jù)參數(shù)讀出相應(yīng)的數(shù)據(jù)。
doc:https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/IOUtils.html
apache下載:
https://commons.apache.org/proper/commons-lang/

五,org.apache.commons.beanutils.BeanUtils Bean工具類
1、copyPeoperties:復(fù)制對象中的所有屬性
2、getProperty:獲取對象中的某個屬性值
3、setProperty:設(shè)置對象中的某個屬性值
4、copyPeoperty:復(fù)制對象中的某個屬性
5、cloneBean:克隆Bean對象到其他對象
doc:https://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.3/apidocs/org/apache/commons/beanutils/BeanUtils.html
apache下載:
https://commons.apache.org/proper/commons-lang/

六,org.apache.commons.codec.digest.DigestUtils 加解密工具類
1、md5Hex:使用md5加密,得到一個32位字符串(16進(jìn)制)
2、sha1Hex:使用sha-1加密,返回一個字符串(16進(jìn)制)
3、sha256Hex:使用sha-256加密,返回一個字符串(16進(jìn)制)
4、sha512Hex:使用sha-512加密,返回一個字符串(16進(jìn)制)
doc:https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/digest/DigestUtils.html
apache下載:
https://commons.apache.org/proper/commons-lang/

小結(jié):
apache提供眾多commons工具包,被稱為Java第二API,在一般的使用中都會被引用,這點開發(fā)者深有體會,對于代碼的可讀性和編碼效率的提升,都都非常有幫助。