1. 是否为 null
  2. 是否为 ""
  3. 是否为空字符串(引号中间有空格)  如: "     "。
  4. 制表符、换行符、换页符和回车

一. 字符串

1. if(str == null || str == "")                 非空 if(str != null && str != "")

2. if(str == null || str.isEmpty())                  if(str != null && !str.isEmpty())

3.if (str == null  || "".equals(str.trim()))       if (str != null && !"".equals(str.trim()))

4.if(str == null   || str.length()<=0)              if(str != null && str.length()>0)

5.if(str == null || "".equals(str))                  if(str != null && !"".equals(str))

6.if(StringUtils.isBlank(str))                       if(StringUtils.isNotBlank(str))                  import org.apache.commons.lang3.StringUtils;判断的是str.length(),相当于4

二.数组

1.arr==null || (arr!=null &&arr.length==0)           非空  arr!=null || (arr==null &&arr.length!=0)

三.List集合

1.if(list == null || list.isEmpty())            非空  if(list != null && !list.isEmpty())

2.if(list == null || list.size() == 0)                    if(list != null && list.size() > 0)

3.if(list == null || StringUtils.isEmpty(list))     if(list != null && !StringUtils.isEmpty(list))

4.if (CollectionUtils.isEmpty(list))                  if (CollectionUtils.isNotEmpty(list))      等同于2

四.Map

1.if (MapUtils.isEmpty(map))                    非空  if (MapUtils.isNotEmpty(map))      等同于2

2.if(map== null || map.size() == 0)                     if(map!= null && map.size() > 0)

3.if(map== null || StringUtils.isEmpty(map))      if(map!= null && !StringUtils.isEmpty(map))

null和isEmpty()的区别

  1. 这就相当于去商店买东西
  2.  null 首先判断是否有商店(new ArrayList();)
  3.  isEmpty()没有判断商店是否存在,而是判断商店是否有东西,如果连商店都没有,何来的的东西可卖(list.add(商品))

最新文章

  1. [AlwaysOn Availability Groups]健康模型 Part 1——概述
  2. vlc 在ie11 中的addEventListener事件不触发
  3. CentOS下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)
  4. IIS+WebMatrix 做 PHP 遇到的问题总结
  5. assets
  6. UIImageView之我的动画为什么停了?UIImageView, highLighted,animationImages
  7. python基础-软件目录开发规范
  8. [bilibili]弹幕屏蔽列表
  9. windows平台MySQL密码设置与破解
  10. java基础 ---- 练习for循环
  11. 【转载】java对象和byte数组互转,直接拿去用
  12. java与xml转换 -- XStreamAlias
  13. .3-浅析express源码之applicaiton模块(2)-app.render
  14. MySQL 查询优化简记
  15. sudo: add-apt-repository: command not found
  16. 【转载】Java动态代理之JDK实现和CGlib实现(简单易懂)
  17. Maven新建一个Spring MVC项目
  18. odps编写UDF的实现
  19. (beta冲刺5/7)
  20. jrtplib源码分析 第一篇 jthread的编译与分析

热门文章

  1. 【Wine使用经验分享】Wine字体显示问题处理
  2. Leetcode链表
  3. AgileBoot - 基于SpringBoot + Vue3的前后端快速开发脚手架
  4. Windows开启关闭测试模式的方法(含开启测试模式失败的解决办法)
  5. 一键体验 Istio
  6. 深入浅出TCP与IP协议笔记
  7. 三十三、HPA实现自动扩缩容
  8. springboot整合项目-商城个人头像上传功能
  9. 高性能MySQL(第4版) 第一章 MySQL架构 读书笔记
  10. AGC007C Pushing Balls —— 期望的神题