如何比较两个的ArrayList<名单,LT;弦乐>> [英] How to compare two ArrayList<List<String>>

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

问题描述

我想比较这两种的ArrayList

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

如果他们有相同的元素,它将返回true,否则为false。

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

推荐答案

您可以尝试使用Apache的 Col​​lectionUtils.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的大小等于 arrayList1 arrayList2 你可以说这两个单子都是一样的。

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

这篇关于如何比较两个的ArrayList&LT;名单,LT;弦乐&GT;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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