java中对对象进行判空的操作

首先来看一下工具StringUtils的判断方法:

一种是org.apache.commons.lang3包下的;

另一种是org.springframework.util包下的。这两种StringUtils工具类判断对象是否为空是有差的

org.apache.commons.lang3包

StringUtils.isEmpty(CharSequence cs); //org.apache.commons.lang3包下的StringUtils类,判断是否为空的方法参数是字符序列类,也就是String类型

org.springframework.util包

StringUtils.isEmpty(Object str); //而org.springframework.util包下的参数是Object类,也就是不仅仅能判断String类型,还能判断其他类型,比如Long等类型。

下面来看一下org.apache.commons.lang3的StringUtils.isEmpty(CharSequence cs)源码:

public static boolean isEmpty(final CharSequence cs) {
return cs == null || cs.length() == 0;
}

接下来是org.springframework.util的StringUtils.isEmpty(Object str)源码:

public static boolean isEmpty(Object str) {
return (str == null || "".equals(str));
}

最新文章

  1. 比较数据泵和exp/imp对相同数据导出/导入的性能差异
  2. [Nginx][HttpUpstreamModule]翻译负载均衡
  3. UVa 103 - Stacking Boxes(dp求解)
  4. OpenStack在线迁移
  5. Android 应用中十大常见 UX 错误
  6. 2016多校联合训练contest4 1012Bubble Sort
  7. JS动画理论
  8. access 2007 vba 开发中学到的知识(三)
  9. React 组件开发初探
  10. raspberrypi VNC server
  11. Shiro入门(1)
  12. Python从json中提取数据
  13. 阿里云大数据计算服务 - MaxCompute (原名 ODPS)
  14. Android开发者的Anko使用指南(一)之Intent
  15. Darwin Streaming Server服务器mp4文件点播返回”415 Unsupported Media Type“错误
  16. inheritPrototypal.js
  17. vue报错/ style-loader: Adds some css to the DOM by adding a <style> tag
  18. js之create()
  19. 404 Note Found 队-Beta1
  20. Anaconda+django写出第一个web app(三)

热门文章

  1. 比较两个CSV的方法的探索
  2. 系统权限划分Liunx版
  3. 8-网页,网站,微信公众号基础入门(使用Python程序实现微信token验证)
  4. 同余方程组(EXCRT)(luogu4777)
  5. CCF 201909-4 推荐系统
  6. 切比雪夫定理(Chebyshev's theorem)与经验法则(Empirical Rule)
  7. 【JZOJ6232】【20190625】喜欢最最痛
  8. js之select三级联动
  9. MyBatis传入参数为list、数组、map写法
  10. ubuntu之路——day17.1 用np.pad做padding