CollectionUtils工具类
CollectionUtils工具类
这篇讲的CollectionUtils工具类是在apache下的,可以使代码更加简洁和安全。
使用前需导入依赖
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.3</version>
</dependency>
API常用方法
/**
* 1、除非元素为null,否则向集合添加元素
*/
CollectionUtils.addIgnoreNull(personList,null);
/**
* 2、将两个已排序的集合a和b合并为一个已排序的列表,以便保留元素的自然顺序
*/
CollectionUtils.collate(Iterable<? extends O> a, Iterable<? extends O> b)
/**
* 3、将两个已排序的集合a和b合并到一个已排序的列表中,以便保留根据Comparator c的元素顺序。
*/
CollectionUtils.collate(Iterable<? extends O> a, Iterable<? extends O> b, Comparator<? super O> c)
/**
* 4、返回该个集合中是否含有至少有一个元素
*/
CollectionUtils.containsAny(Collection<?> coll1, T... coll2)
/**
* 5、如果参数是null,则返回不可变的空集合,否则返回参数本身。(很实用 ,最终返回List EMPTY_LIST = new EmptyList<>())
*/
CollectionUtils.emptyIfNull(Collection<T> collection)
/**
* 6、空安全检查指定的集合是否为空
*/
CollectionUtils.isEmpty(Collection<?> coll)
/**
* 7、 空安全检查指定的集合是否为空。
*/
CollectionUtils.isNotEmpty(Collection<?> coll)
/**
* 8、反转给定数组的顺序。
*/
CollectionUtils.reverseArray(Object[] array);
/**
* 9、差集
*/
CollectionUtils.subtract(Iterable<? extends O> a, Iterable<? extends O> b)
/**
* 10、并集
*/
CollectionUtils.union(Iterable<? extends O> a, Iterable<? extends O> b)
/**
* 11、交集
*/
CollectionUtils.intersection(Collection a, Collection b)
/**
*12、 交集的补集(析取)
*/
CollectionUtils.disjunction(Collection a, Collection b)
CollectionUtils工具类的更多相关文章
- java代码之美(12)---CollectionUtils工具类
java代码之美(12)---CollectionUtils工具类 这篇讲的CollectionUtils工具类是在apache下的, 而不是springframework下的CollectionUt ...
- StringUtils、CollectionUtils工具类的常用方法
唯能极于情,故能极于剑 欢迎来到 “程序牛CodeCow” 的博客,有问题请及时关注小编公众号 “CodeCow”,大家一起学习交流 下面将为大家演示StringUtils.CollectionUti ...
- java代码(12) ---CollectionUtils工具类
CollectionUtils工具类 CollectionUtils工具类是在apache下的,而不是springframework下的CollectionUtils 个人觉得在真实项目中Collec ...
- 通过CollectionUtils工具类判断集合是否为空,通过StringUtils工具类判断字符串是否为空
通过CollectionUtils工具类判断集合是否为空 先引入CollectionUtils工具类: import org.apache.commons.collections4.Collectio ...
- CollectionUtils工具类之并集union(arr1,arr2)和差集subtract(arr1,arr2)
一.CollectionUtils工具类之并集union(arr1,arr2)和差集subtract(arr1,arr2) 采用的类: import org.apache.commons.collec ...
- CollectionUtils工具类的常用方法
集合判断: 例1: 判断集合是否为空: CollectionUtils.isEmpty(null): true CollectionUtils.isEmpty(new ArrayList()): t ...
- CollectionUtils工具类中常用方法
@SuppressWarnings("rawtypes") @Test public void test1() { List<String> coll = new Ar ...
- CollectionUtils工具类使用指南
CollectionUtils提供很多对集合的操作方法,常用的方法如下:(参考文章:http://www.open-open.com/code/view/1420470842125) import o ...
- 集合工具类CollectionUtils、ListUtils、SetUtils、MapUtils的使用
主要用它的isEmpty(final Collection<?> coll)静态方法来判断一个给定的集合是否为null或者是否长度为0.最近才发现此工具类还可以取集合的交集.并集.甚至差集 ...
随机推荐
- http跳转http
server {listen 80;server_name 123.com;root /var/www/web/123;index index.html index.htm index.php;rew ...
- 透过F5获取服务器真实内网IP
渗透测试过程中,经常会遇到目标服务器使用F5 LTM做负载均衡. 如果能获取到目标服务器的真实IP地址,会给后续渗透带来一定便利. 本文既是最近渗透遇到的一点点经验分享. F5修改cookie机制 F ...
- git 学习系列(一)
目录 git 简介 git的升级 建立仓库 克隆仓库 查看主机名 查看仓库初始状态 将文件提交到暂存区 查看修改详情 提交修改 查看修改记录 查看个人配置信息(在 .gitconfig 文件中) 查看 ...
- ORs-3-OR Gene Family Phylogeny
OR Gene Family Phylogeny 1.之前关于ORs基因构建系统生发树的研究中的不足:bootstrap support values在有些family中高,bootstrap sup ...
- Linux下停止和启动redis
1.停止redis (进入redis安装目录) [root@JDu4e00u53f7 redis]# ./bin/redis-cli shutdown 2. 启动redis [root@JDu4e00 ...
- js求两个数的百分比
function toPercent(num, total) { return (Math.round(num / total * 10000) / 100.00 + "%");/ ...
- C#结构体的使用
C#结构体的使用 结构体:相当于是我们自己定义的一种复杂的类型. 常见简单类型:int... double float bool char string 常见复杂类型:DateTime 数组类型 生活 ...
- OpenCV 图像平滑处理
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" us ...
- Qt QString与string的转换
QString --> string QString.toStdString(); string --> QString QString::fromStdString(string);
- 使用iframe的好处与坏处详细比拼
一.使用iframe的坏处 1.搜索引擎的蜘蛛不会识别在iframe中被调用的图片.文本.url等内容的,因为该内容不属于该页面,只是访问的时候被临时的调用,而且在SEO建议中也有提到:"f ...