当前位置:网站首页>【code】if (list != null && list.size() > 0)优化,集合判空实现方式
【code】if (list != null && list.size() > 0)优化,集合判空实现方式
2022-07-03 06:30:00 【掘金者说】
写旧了,写高频,想换中口味…
就是这样: if(list != null && list.size() > 0) ===》 CollectionUtils.isNotEmpty(list);
if (list != null && list.size() > 0) {
//TODO 执行逻辑
}
//import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
if (CollectionUtils.isNotEmpty(list)) {
//TODO 执行逻辑
}
/** * Collection工具类 * * @author Caratacus * @since 2016-09-19 */
public class CollectionUtils {
/** * 校验集合是否为空 * * @param coll 入参 * @return boolean */
public static boolean isEmpty(Collection<?> coll) {
return (coll == null || coll.isEmpty());
}
/** * 校验集合是否不为空 * * @param coll 入参 * @return boolean */
public static boolean isNotEmpty(Collection<?> coll) {
return !isEmpty(coll);
}
......
}
依照方式,优雅体现
边栏推荐
- Simple understanding of ThreadLocal
- 100000 bonus is divided up. Come and meet the "sister who braves the wind and waves" among the winners
- 剖析虚幻渲染体系(16)- 图形驱动的秘密
- Openresty best practices
- How to scan when Canon c3120l is a network shared printer
- opencv
- Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
- Simple password lock
- Kubesphere - build Nacos cluster
- Characteristics and isolation level of database
猜你喜欢
JMeter linked database
Kubesphere - set up redis cluster
. Net program configuration file operation (INI, CFG, config)
Ruoyi interface permission verification
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
Kubesphere - build MySQL master-slave replication structure
【无标题】
YOLOV3学习笔记
Zhiniu stock project -- 05
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
随机推荐
Project summary --04
DNS forward query:
pytorch练习小项目
学习笔记 -- k-d tree 和 ikd-Tree 原理及对比
Code management tools
How matlab modifies default settings
Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
Luogu problem list: [mathematics 1] basic mathematics problems
Common interview questions
堆排序和优先队列
Tabbar settings
Mysql
Support vector machine for machine learning
Cannot get value with @value, null
Naive Bayes in machine learning
【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案
冒泡排序的简单理解
error C2017: 非法的转义序列
使用conda创建自己的深度学习环境
Climb movie paradise 2021 hot