java中对对象进行判空的操作--简洁编码
2024-09-22 02:15:58
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));
}
最新文章
- 比较数据泵和exp/imp对相同数据导出/导入的性能差异
- [Nginx][HttpUpstreamModule]翻译负载均衡
- UVa 103 - Stacking Boxes(dp求解)
- OpenStack在线迁移
- Android 应用中十大常见 UX 错误
- 2016多校联合训练contest4 1012Bubble Sort
- JS动画理论
- access 2007 vba 开发中学到的知识(三)
- React 组件开发初探
- raspberrypi VNC server
- Shiro入门(1)
- Python从json中提取数据
- 阿里云大数据计算服务 - MaxCompute (原名 ODPS)
- Android开发者的Anko使用指南(一)之Intent
- Darwin Streaming Server服务器mp4文件点播返回”415 Unsupported Media Type“错误
- inheritPrototypal.js
- vue报错/ style-loader: Adds some css to the DOM by adding a <;style>; tag
- js之create()
- 404 Note Found 队-Beta1
- Anaconda+django写出第一个web app(三)
热门文章
- 比较两个CSV的方法的探索
- 系统权限划分Liunx版
- 8-网页,网站,微信公众号基础入门(使用Python程序实现微信token验证)
- 同余方程组(EXCRT)(luogu4777)
- CCF 201909-4 推荐系统
- 切比雪夫定理(Chebyshev&#39;s theorem)与经验法则(Empirical Rule)
- 【JZOJ6232】【20190625】喜欢最最痛
- js之select三级联动
- MyBatis传入参数为list、数组、map写法
- ubuntu之路——day17.1 用np.pad做padding