返回java中两个列表之间的差异 [英] returning difference between two lists in java

查看:133
本文介绍了返回java中两个列表之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据列表,例如

I have two array lists e.g.

List<Date> a;
contains : 10/10/2014, 10/11/2016

List<Date> b;
contains : 10/10/2016

如何在列表<$之间进行检查c $ c> a 和 b 因此返回 b 中缺少的值?例如 10/10/2014

How can i do a check between list a and b so the value that is missing in b is returned?e.g. 10/10/2014

推荐答案

您可以将它们转换为设置集合,并对它们执行设置差异操作。

You can convert them to Set collections, and perform a set difference operation on them.

像这样:

Set<Date> ad = new HashSet<Date>(a);
Set<Date> bd = new HashSet<Date>(b);
ad.removeAll(bd);

这篇关于返回java中两个列表之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆