java中常用的工具类
一、字符串相关工具类
(1)org.apache.commons.lang.StringUtils:处理字符串的相关操作
- isBlank ( )
- isNotBlank ( )
- isEmpty ( )
- isNotEmpty ( )
- equals ( )
- join ( )
- split ( )
- EMPTY
- trimToNull ( )
- replace ( )
(2)org.apache.commons.lang3.StringUtils:处理字符串的相关方法 与上面的功能差不多
- isBlank ( )
- isNotBlank ( )
- isEmpty ( )
- isNotEmpty ( )
- join ( )
- equals ( )
- split ( )
- EMPTY
- replace ( )
- capitalize ( )
(3)org.springframework.util.StringUtils:处理字符串的方法
- hasText ( )
- hasLength ( )
- isEmpty ( )
- commaDelimitedListToStringArray ( )
- collectionToDelimitedString ( )
- replace ( )
- delimitedListToStringArray ( )
- uncapitalize ( )
- collectionToCommaDelimitedString ( )
- tokenizeToStringArray ( )
(4)org.apache.commons.lang.StringEscapeUtils:处理字符串的方法
- escapeHtml ( )
- unescapeHtml ( )
- escapeXml ( )
- escapeSql ( )
- unescapeJava ( )
- escapeJava ( )
- escapeJavaScript ( )
- unescapeXml ( )
- unescapeJavaScript ( )
(5)org.apache.commons.lang3.StringEscapeUtils:字符串转义方法
- unescapeHtml4 ( )
- escapeHtml4 ( )
- escapeXml ( )
- unescapeXml ( )
- escapeJava ( )
- escapeEcmaScript ( )
- unescapeJava ( )
- escapeJson ( )
- escapeXml10 ( )
二、数组相关工具类
(1)java.util.Arrays :java中自有的数组处理工具类
(2)org.apache.commons.lang.ArrayUtils:数组操作方法
- contains ( )
- addAll ( )
- clone ( )
- isEmpty ( )
- add ( )
- EMPTY_BYTE_ARRAY
- subarray ( )
- indexOf ( )
- isEquals ( )
- toObject ( )
(3)org.apache.commons.lang3.ArrayUtils:数组操作方法
- contains ( )
- isEmpty ( )
- isNotEmpty ( )
- add ( )
- clone ( )
- addAll ( )
- subarray ( )
- indexOf ( )
- EMPTY_OBJECT_ARRAY
- EMPTY_STRING_ARRAY
三、集合相关工具类
集合操作相关工具类比较多,暂且只列出以下三种
(1)java.util.Collections:java自有的集合操作工具类
(2)org.springframework.util.CollectionUtils :spring框架带有的集合操作工具类
(3)org.apache.commons.collections.CollectionUtils:集合操作方法
- isEmpty ( )
- isNotEmpty ( )
- select ( )
- transform ( )
- filter ( )
- find ( )
- collect ( )
- forAllDo ( )
- addAll ( )
- isEqualCollection ( )
四、文件操作相关工具类
(1)org.apache.commons.io.FileUtils:处理文件的相关操作
- deleteDirectory ( )
- readFileToString ( )
- deleteQuietly ( )
- copyFile ( )
- writeStringToFile ( )
- forceMkdir ( )
- write ( )
- listFiles ( )
- copyDirectory ( )
- forceDelete ( )
(2)org.apache.commons.io.FilenameUtils:处理文件名的相关方法
- getExtension ( )
- getBaseName ( )
- getName ( )
- concat ( )
- removeExtension ( )
- normalize ( )
- wildcardMatch ( )
- separatorsToUnix ( )
- getFullPath ( )
- isExtension ( )
五、IO流操作相关工具类
(1)org.apache.commons.io.IOUtils:处理IO流的相关操作
- closeQuietly ( )
- toString ( )
- copy ( )
- toByteArray ( )
- write ( )
- toInputStream ( )
- readLines ( )
- copyLarge ( )
- lineIterator ( )
- readFully ( )
六、加密相关工具类
(1)org.springframework.util.DigestUtils :spring框架自带的加密工具类
(2)org.apache.commons.codec.digest.DigestUtils:消息加密工具方法,消息可以是字符串,io流,字节数组
- md5Hex ( )
- shaHex ( )
- sha256Hex ( )
- sha1Hex ( )
- sha ( )
- md5 ( )
- sha512Hex ( )
- sha1 ( )
七、java bean相关操作工具类
(1)org.apache.commons.beanutils.PropertyUtils:java bean操作方法
- getProperty ( )
- setProperty ( )
- getPropertyDescriptors ( )
- isReadable ( )
- copyProperties ( )
- getPropertyDescriptor ( )
- getSimpleProperty ( )
- isWriteable ( )
- setSimpleProperty ( )
- getPropertyType ( )
(2)org.apache.commons.beanutils.BeanUtils:java bean操作方法
- copyProperties ( )
- getProperty ( )
- setProperty ( )
- describe ( )
- populate ( )
- copyProperty ( )
- cloneBean ( )
(3)org.springframework.beans.BeanUtils 建议使用这个
八、其他工具类
(1)org.apache.http.util.EntityUtils:处理HttpEntity类的静态方法
- toString ( )
- consume ( )
- toByteArray ( )
- consumeQuietly ( )
- getContentCharSet ( )
九、推荐hutool工具包
hutool工具包里面封装了大多数的工具类,可以不用再去多封装一些工具类了,即不用重复造轮子,使用时在项目pom文件中引入依赖即可,如下:
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.4.3</version>
</dependency>
项目源码地址:https://github.com/looly/hutool 官方文档: https://www.hutool.cn/
参考博文:
(1)https://www.jb51.net/article/167156.htm
(2)https://www.jianshu.com/p/6a372ee8bfb9