如何比较两个ArrayList<List<String>> [英] How to compare two ArrayList&lt;List&lt;String&gt;&gt;

查看:47
本文介绍了如何比较两个ArrayList<List<String>>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较这两个ArrayList:

public static ArrayList<List<String>> arrayList1 = new ArrayList<List<String>>();
public static ArrayList<List<String>> arrayList2 = new ArrayList<List<String>>();

如果它们具有相同的元素,则返回真,否则返回假.

If they have the same elements it will return true, otherwise false.

推荐答案

您可以尝试使用 Apache commons CollectionUtils.retainAll 方法:返回一个包含collection1 中所有也在 collection2 中的元素.

You can try using Apache commons CollectionUtils.retainAll method : Returns a collection containing all the elements in collection1 that are also in collection2.

ArrayList commonList = CollectionUtils.retainAll(arrayList1, arrayList2);

如果commonList的大小等于arrayList1arrayList2,你可以说这两个列表是一样的.

If the size of commonList is equal to arrayList1 and arrayList2 you can say both the list are same.

这篇关于如何比较两个ArrayList<List<String>>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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