In Java, there are many practical class libraries, and they usually define a series of methods with common functions. This article summarizes the most commonly used utility classes in Java and their most commonly used methods. Both classes and methods within classes are sorted by popularity.
The classes and methods listed in this article are commonly used class libraries and methods that have gone through a lot of practice, and we can use them directly. Of course, we can implement the functions implemented by these methods ourselves, but since there are already very mature methods for us to use, there is no need to define them ourselves. Many classes and methods can actually understand what they do through their names. Each method has a link to see how it is used in open source code.
The following list is derived by analyzing 50K open source projects.
1. org.apache.commons.io.IOUtils
closeQuietly ( )
toString ( )
copy ( )
toByteArray ( )
write ( )
toInputStream ( )
readLines ( )
copyLarge ()
writeStringToFile ( )forceMkdir ( )write ( )listFiles ( )copyDirectory ( )forceDelete ( )3. org.apache.commons.lang.StringUtilsisBlank ( )isNotBlank ( )isEmpty ( )isNotEmpty ( )equals ( )join ( )split ( )EMPTYtrimToNull ( )replace ( )4. org.apache.http.util.Entity Utils toString ( )consume ( )toByteArray ( )consumeQuietly ( )getContentCharSet ( )5. isNotBlank ( ) isEmpty ( )isNotEmpty ( )join ( )equals ( )split ( )EMPTYreplace ( )capitalize ( )6. org.apache.commons.io.FilenameUtils
getExtension ()getBaseName () isExtension ( )
7. org.springframework.util.StringUtilshasText ( )hasLength ( )isEmpty ( )commaDelimitedListToStringArray ( )collectionToDelimitedString ( )replace ( )de limitedListToStringArray ( )uncapitalize ( ) collectionToCommaDelimitedString ( )tokenizeToStringArray ( )8. org.apache.commons.lang.ArrayUtilscontains ( )addAll ( )clone ( )isEmpty ( )
add ( ) EMPTY_BYTE_ARRAYsubarray () escapeXml ( )
escapeSql ( )unescapeJava ( )escapeJava ( )escapeJavaScript ( )unescapeXml ( )unescapeJavaScript ( )10. org.apache.http.client.utils.URLEncodedUtilsformat ( )
parse ()
sha512Hex ()sha1 ()
find ( )
collect ( )
forAllDo ( )
addAll ( )
isEqualCollection ( )
13. org.apache.commons.lang3.ArrayUtils
contains ( )
isEmpty ( )
isNotEmpty ( )
add ( )
clone ( )
addAll ( )
subarray ( )
indexOf ( )
EMPTY_OBJECT_ARRAY
EMPTY_STRING_ARRAY
14. org.apache.commons.beanutils .PropertyUtils
getProperty ( )
setProperty ( )
getPropertyDescriptors ( )
isReadable ( )
copyProperties ( )
getPropertyDescriptor ( )
getSimpleProperty ( )
isWriteable ( )
setSimpleProperty ( )
getPropertyType ( )
15. org. apache.commons.lang3.StringEscapeUtils
unescapeHtml4 ( )
escapeHtml4 ( )
escapeXml ( )
unescapeXml ( )
escapeJava ( )
escapeEcmaScript ( )
unescapeJava ( )
escapeJson ( )
escapeXml10 ( )
16. org.apache.commons.beanutils.BeanUtils
copyProperties ( )
getProperty ( )
setProperty ( )
describe ( )
populate ( )
copyProperty ( )
cloneBean ( )