如何返回两个列表之间的差异? [英] How can I return the difference between two lists?

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

问题描述

我有两个数组列表,例如

I have two array lists e.g.

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

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

我如何在列表ab之间进行检查,以便返回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屋!

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