• 实用的 集合工具类 和 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



     



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

       
  • 相关阅读:
    数据库数据闪回设置
    Ajax
    Spring Framework & Spring Boot
    Maven与Ant比较
    Spring中控制反转(IoC)/依赖注入(DI)的区别
    C# 图片加水印、截取图片、压缩图片等。有个坑,往下看。当图片为jpg格式时,发现出来的图片结果异常的大
    json 递归
    Webservice 问题:system.argumentexception:找不到xxx定义。缺少命名空间为xxx的服务说明
    利用.net 自带的工具生成webservice服务(windows)
    sqlserver 查询 今天明天后天等数据
  • 原文地址:https://www.cnblogs.com/hqlong/p/6430090.html
Copyright © 2020-2023  润新知