zoukankan      html  css  js  c++  java
  • 工具类系列---【如何优雅的对String,List,Map判空?】

    1、导入maven坐标:

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.9</version>
    </dependency>

    2、StringUtils

    //对String类型的字符串进行判空
    String s = "今天天气正好";
    StringUtils.isNotBlank(s);
    StringUtils.isEmpty(s);
    

    3.CollectionUtils

    //对单列集合Collection判空
    List array = new ArrayList();
    CollectionUtils.isNotEmpty(array); 
    

    4.MapUtils

    //在Map集合中根据key取value,内部都会做一个隐式判空
    Map<String,Object> map = new HashMap();
    map.put("str","字符串");
    map.put("array",new ArrayList<>());
    map.put("mapChild","new HashMap()");
    String str = MapUtils.getString(map,"str");
    List array = (List) MapUtils.getObject(map,"array");
    Map mapChild = MapUtils.getMap(map,"mapChild");
    

      

    愿你走出半生,归来仍是少年!
  • 相关阅读:
    系统运维易忘点总结之七
    SqlServer的排序规则
    Oracle数据库用户密码过期解决
    linux 查看即时网速 /流量的工具
    NFS部署过程
    NFS 共享存储
    Rsync服务的实战
    ncRsync服务
    架构名词
    状态码
  • 原文地址:https://www.cnblogs.com/hujunwei/p/14005005.html
Copyright © 2011-2022 走看看