Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common tool classes in Java

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about the commonly used tools in Java, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

# I. Preface

In Java, utility classes define a set of common methods, and this article introduces the most frequently used and general-purpose Java utility classes in Java. The following tool categories and methods are ranked by popularity. The reference data come from 50, 000 open source projects randomly selected on Github.

# II. Org.apache.commons.io.IOUtils

Java closeQuietly: close an IO stream, socket, or selector without throwing an exception, usually put in the finally block toString: convert IO stream, Uri, byte [] to String copy:IO stream data replication, write from input stream to output stream, maximum support 2GB toByteArray: get byte [] write from input stream, URI: put bytes. Write characters to output stream toInputStream: convert characters to input stream readLines: read multiple lines of data from the input stream, return List copyLarge: same as copy, support replication of data above 2GB lineIterator: return an iterator from the input stream, read all the data read according to the parameter requirements, and fail if the data is not enough

# III. Org.apache.commons.io.FileUtils``javadeleteDirectory: delete folder readFileToString: read file contents as characters deleteQueitly: delete files or folders without throwing exceptions copyFile: copy files writeStringToFile: write characters to the target file, if the file does not exist, create forceMkdir: force the creation of a folder, if the folder parent directory does not exist Then create a parent write: write characters to a specified file listFiles: enumerate files in a directory (according to filter) copyDirectory: copy folder forceDelete: force deletion of files

# IV. Org.apache.commons.lang.StringUtils

IsBlank: whether the string is empty (determine after trim) isEmpty: whether the string is empty (do not trim and determine) equals: whether the string is equal join: merge the array into a single string, split: split string EMPTY: if the empty string is returned after trimToNull:trim, it is converted to nullreplace: replace the string

# 5. Org.apache.http.util.EntityUtils

ToString: convert Entity to string consume: make sure that all the content in Entity is consumed. You can see that the content of Entity is consumed again in the source code. If the user does not consume it, the call to Entity will consume it toByteArray: convert Entity to byte stream consumeQuietly: same as consume, but no exception getContentCharset: get the encoding of the content

# VI. Org.apache.commons.lang3.StringUtils

IsBlank: whether the string is empty (determine after trim) isEmpty: whether the string is empty (do not trim and determine) equals: whether the string is equal join: merge the array into a single string, split: split string EMPTY: return empty string replace: replace string capitalize: first character uppercase

# VII. Org.apache.commons.io.FilenameUtils

GetExtension: return file suffix name getBaseName: return file name, excluding suffix name getName: return file full name concat: combine file path according to command line style (see method notes for details) removeExtension: delete suffix name normalize: normalize the path wildcardMatch: match wildcard seperatorToUnix: path separator is changed to unix system format, that is, / getFullPath: get the file path, excluding the file name isExtension: check whether the file suffix name is one of the incoming parameters (List)

# VIII. Org.springframework.util.StringUtils

HasText: check whether the string contains text hasLength: detect whether the string length is greater than 0isEmpty: detect whether the string is empty (if passed as an object, determine whether the object is null) commaDelimitedStringToArray: comma-delimited String converted to an array collectionToDelimitedString: convert the collection to CSV format string replace replacement string delimitedListToStringArray: equivalent to splituncapitalize: first letter lowercase collectionToDelimitedCommaString: convert the collection to CSV format string tokenizeToStringArray: basically the same as split But it can automatically remove blank words.

# IX. Org.apache.commons.lang.ArrayUtils

Contains: whether to include a string addAll: add an entire array clone: clone an array isEmpty: whether empty array add: add elements to an array subarray: truncated array indexOf: find the subscript of an element isEquals: compare whether the array is equal toObject: convert the basic type data array to the corresponding Object array

# 10. Org.apache.commons.lang.StringEscapeUtils

Reference 16: org.apache.commons.lang3.StringEscapeUtils

# 11. Org.apache.http.client.utils.URLEncodedUtils

Format: format parameter that returns a HTTP POST or HTTP PUT available application/x-www-form-urlencoded string parse: converts String or URI to List

# 12. Org.apache.commons.codec.digest.DigestUtils

Md5Hex:MD5 encryption, return 32-bit string, sha1Hex:SHA-1 encryption, sha256Hex:SHA-256 encryption, sha512Hex:SHA-512 encryption, md5:MD5 encryption, return 16-bit string

# XIII. Org.apache.commons.collections.CollectionUtils

IsEmpty: empty select: filter collection elements according to conditions transform: handle collection elements according to the specified method, map () filter: filter elements similar to List, filter () find like List: basically the same as select collect: almost the same as transform, but return a new array forAllDo: call the specified method of each element isEqualCollection: determine whether the two collections are consistent

# 14. Org.apache.commons.lang3.ArrayUtils

Contains: whether to include a string addAll: add an entire array clone: clone an array isEmpty: whether empty array add: add elements to an array subarray: truncated array indexOf: find the subscript of an element isEquals: compare whether the array is equal toObject: convert the basic type data array to the corresponding Object array

# 15. Org.apache.commons.beanutils.PropertyUtils

GetProperty: get object property values setProperty: set object property values getPropertyDiscriptor: get property descriptors isReadable: check whether properties are accessible copyProperties: copy property values, from one object to another object getPropertyDiscriptors: get all attribute descriptors isWriteable: check whether attributes are writable getPropertyType: get object property types

# 16. Org.apache.commons.lang3.StringEscapeUtils

UnescapeHtml4: escape htmlescapeHtml4: reverse htmlescapeXml: escape xmlunescapeXml: escape xmlescapeJava: escape unicode Encoding escapeEcmaScript: escape EcmaScript character unescapeJava: escape unicode Encoding escapeJson: escape json character escapeXml10: escape Xml10 this has been abandoned, it is recommended to use the method in commons-text package.

# XVII. Org.apache.commons.beanutils.BeanUtils

CopyPeoperties: copy attribute values, from one object to another getProperty: get object property values setProperty: set object property values populate: copy copyPeoperty to the property according to Map: copy a single value, from one object to another object cloneBean: clone bean instance now as long as you know the above 16 most popular tool class methods, you no longer need to write your own tool class, do not have to repeat to build wheels. Most utility methods can understand their purpose by their name, if not, you can take a look at how others use it, or check its usage online.

After reading the above, do you have any further understanding of the common tool classes in Java? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report