如何返回两个列表之间的差异? [英] How can I return the difference between two lists?
本文介绍了如何返回两个列表之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个数组列表,例如
I have two array lists e.g.
List<Date> a;
contains : 10/10/2014, 10/11/2016
List<Date> b;
contains : 10/10/2016
我如何在列表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
推荐答案
您可以将它们转换为Set
集合,并对它们执行集合差操作.
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);
这篇关于如何返回两个列表之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文