本文介绍了有没有办法找到多个列出了常见的元素呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有整型数组列表。我需要找到那些之间的共同之处。我能想到的是什么是

I have a list of integer arrays. I need to find the common elements between those. What I can think of is an extension of what is listed in Common elements in two lists

Example would be
[1,3,5],
[1,6,7,9,3],
[1,3,10,11]

should result in [1,3]

里有数组没有重复以及

有没有一种简单的方法来做到这一点?

Is there a straight forward way to do this?

推荐答案

您可以转换列表来台,然后用 Set.retainAll 方法不同之间的交叉集。
一旦你所有的相交集,你会留下共同的元素,您可以将结果集返回到列表中。

You can transform the lists to sets, and then use Set.retainAll method for intersection between the different sets.Once you intersect all sets, you are left with the common elements, and you can transform the resulting set back to a list.

这篇关于有没有办法找到多个列出了常见的元素呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 15:32