Summary of efficient java tool classes

Keywords: Apache Attribute Unix

1. org.apache.commons.lang.StringUtils

isBlank: Is the string empty (trim later)
isEmpty: Whether the string is empty (not trim and judge)
equals: Is the string equal
join: a merged array is a single string, passing a delimiter
Split: split string
isNumericSpace: Is it number able before and after removing spaces between strings?
EMPTY: Returns an empty string
isAllLowerCase: Determines if all letters of a string are lowercase
Empty string after trimToNull:trim converts to null
Replace: replace string
deleteWhitespace: Delete blanks
lowerCase: Change uppercase to lowerCase in a string
upperCase: All citations lowercase to upperCase
remove: delete a segment of the current string
repeat: how many times
Use cases:

String a = "12 3    ";
        String b = " ";
        String c = "qwertyuioo";
        String d = "";
        String f = "1 1";
        String g = "QwerTYuioO";
        String h = "administrator";
        String str = StringUtils.deleteWhitespace(a);//123
        boolean flag1 = StringUtils.isEmpty(a);//false
        boolean flag2 = StringUtils.isEmpty(d);//true
        boolean flag22 = StringUtils.isBlank(d);//true
        boolean flag3 = StringUtils.isEmpty(b);//false
        boolean flag4 = StringUtils.isBlank(b);//true
        boolean flag5 = StringUtils.contains(a, "1");//true
        boolean flag6 = StringUtils.equals(a, b);//false
        boolean flag7 = StringUtils.isAllLowerCase(c);//true
        boolean flag8 = StringUtils.isAllUpperCase(c);//false
        boolean flag9 = StringUtils.isNumeric(a);//false
        boolean flag10 = StringUtils.isNumeric(d);//true
        boolean flag11 = StringUtils.isNumericSpace(a);//false
        boolean flag12 = StringUtils.isNumericSpace(f);//true
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(1);
        list.add(2);
        list.add(1);
        list.add(3);
        String str2 = StringUtils.join(list, "--");//1--2--1--2--1--3
        String str3 = StringUtils.lowerCase(g);//qwertyuioo
        String strr3 = StringUtils.remove(h, "istrator");
        String strr4 = StringUtils.replace(h, "t", "xxx");//adminisxxxraxxxor
        String strr5 = StringUtils.repeat("admin", 5);//adminadminadminadminadmin
        String strr9 = StringUtils.upperCase(h);//ADMINISTRATOR

2. org.apache.commons.collections.CollectionUtils
isEmpty: Is it empty
select: Filter collection elements based on conditions
Filter: Filter elements, similar to List's filter()
find: basically the same as select
isEqualCollection: Determines whether two sets are consistent

Use cases:

CollectionUtils.isEmpty(null): true
 CollectionUtils.isEmpty(new ArrayList()): true  
 CollectionUtils.isEmpty({a,b}): false

3. org.apache.commons.beanutils.BeanUtils

copyProperties (Object dest, Object orig): Copy attribute values from one object to another
describe(Object bean): Put the attribute value of a Bean into a Map
populate (Object bean, Map map): Put the value inside the map into the bean
getProperty(Object bean, String name): Gets the object property value
setProperty(Object bean,String name, Object value): Set object property value
populate: Copy attributes based on Map
copyPeoperty: Copy a single value from one object to another
cloneBean: Clone bean instance
Use cases:

//Different objects of the same class require data replication
User user1 = new User();
user1.setName("Zhang San");
User user2 = new User();
// Copy user1 to user2
BeanUtils. copyProperties(user2,user1);

//Converting Object Data to Map
User user = new User();
// Convert Objects to Map
Map userMap = BeanUtils.describe(user);

Map userMap = new HashMap();
User user = new User();
// Convert Map to Object
BeanUtils.populate(user,userMap);

IV. org.apache.commons.io.FilenameUtils

getExtension: Returns the file suffix name

getBaseName: Returns the file name, without the suffix name

getName: Returns the full name of the file

concat: Combine file paths in command-line style (see method notes for details)

removeExtension: Remove suffix name

Normalize: normalize the path

wildcardMatch: matches wildcards

seperatorToUnix: The path separator is changed to unix system format, that is/

getFullPath: Get the file path, not including the file name

isExtension: Check if the file suffix name is one of the incoming parameters (List <String>)

5. org.apache.commons.io.FileUtils
deleteDirectory: Delete folder

readFileToString: Read file contents as characters

deleteQueitly: Delete files or folders without throwing exceptions

copyFile: Copy the file

writeStringToFile: Writes a character to the target file and creates it if it does not exist

forceMkdir: Force the creation of a folder, or create a parent if the folder parent directory does not exist

write: write characters to a specified file

listFiles: List files in a directory (by filter)

CopDirectory: Copy Folder

forceDelete: Force file deletion

Posted by Matt Parsons on Fri, 20 Sep 2019 20:11:02 -0700