实用的 集合工具类 和 String工具类

集合工具类:CollectionUtil
method:

1.isNotEmpty() 不为空

2.isEmpty() 为空

举例:map集合

        Map<String,String> mapA= new HashMap<>();
        Map<String,String> mapB= new HashMap<>();
        Map<String,String> mapC= new HashMap<>();
        mapA.put("1", "1");
        mapB.put(null, null);
        System.out.println(CollectionUtil.isNotEmpty(mapA));//true
        System.out.println(CollectionUtil.isNotEmpty(mapB));//true
        System.out.println(CollectionUtil.isNotEmpty(mapC));//false

String工具类:StringUtil

method:
1.isNotBlank
2.isBlank
        String sA= null;
        String sB= "";
        String sC= "123";
        System.out.println(StringUtil.isNotBlank(sB));//false
        System.out.println(StringUtil.isNotBlank(sA));//false
        System.out.println(StringUtil.isNotBlank(sC));//true

3.alignRight("str", *)  扩展并右对齐字符串,用空格' '填充左边(*为数字类型,可以为负数,表示消除空格数量)

4.alignLeft("str", *)  扩展并右对齐字符串,用空格' '填充左边 (*为数字类型,可以为负数,表示消除空格数量)

5.center("str",*)   用空格' '填充两边。

6.capitalize("str")   将字符串的首字符转成大写(Character.toTitleCase),其它字符不变。

7.chomp("str","separator")   删除字符串末尾的指定字符串。如果字符串不以该字符串结尾,则什么也不做。

8.containsOnly("str","valid")   检查字符串是是否只包含指定字符集合中的字符。但是空字符串永远返回true.

9.containsNone("str", "valid")   检查字符串是是否不包含指定字符集合中的字符。 但是空字符串永远返回true.

10.equals(): 比较两个字符串是否相等,如果两个均为null,则也认为相等

 
  StringUtils.equals("", "");   //true
 
  StringUtils.equals(null, null);  //true
 
  StringUtils.equals(null, "");  //false
 
  StringUtils.equals("",null);  //false
 
  StringUtils.equals(null,"");  //false
 
  StringUtils.equalsIgnoreCase("ss", "Ss");  //不区分大小写--true



 



 还有一些不,不一一贴上来了

   
原文地址:https://www.cnblogs.com/hqlong/p/6430090.html