如何比较两个数组列表? [英] How to compare two arraylist?

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

问题描述

我有两个的ArrayList 。每间大小100000我想对它们进行比较和计数匹配的元素。

I have two ArrayList. Each is of size 100000. I want to compare them and count matched elements.

下面是我的code:

for (int i = 0; i < mArryLst2.size(); i++) {
   if (ArryLst1.contains(mArryLst2.get(i))) {
       matchedPixels++;         
   }
}

下面的比较过程中,走的时候很多。

Here comparison process is taking lot of time.

如何解决和优化这个问题。

How to solve and optimize this problem.

推荐答案

你应该使用 Col​​lectionUtils.retainAll :返回包含collection1这也是所有元素的集合collection2。

you should use CollectionUtils.retainAll : Returns a collection containing all the elements in collection1 that are also in collection2.

ArrayList commonList = CollectionUtils.retainAll(list1,list2);

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

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