多的ArrayList逻辑合 [英] Logical conjunction for multiple arraylists

查看:119
本文介绍了多的ArrayList逻辑合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有多个的ArrayList(的ArrayList的数目是先验未知)。在每一个ArrayList的,我需要找到能够提供与其他列表元素的逻辑相结合的元素。需要注意的是比较仅用于非空值的。

There are multiple arraylists (the number of arraylists is apriori unknown). In each arraylist I need to find an element that provides logical conjunction with elements from other lists. Note that the comparison is made only for non-null values.

ArrayList<Integer[]> list1 = new ArrayList<Integer[]>();
ArrayList<Integer[]> list2 = new ArrayList<Integer[]>();
ArrayList<Integer[]> list3 = new ArrayList<Integer[]>();

list1.add(new Integer[]{1,2,3,4});
list1.add(new Integer[]{1,4,5,6});

list2.add(new Integer[]{1,4,null,null});

list3.add(new Integer[]{null,null,null,5});
list3.add(new Integer[]{null,null,null,6});

在此情况下,答案应该是:

In this case the answer should be:

list1: {1,4,5,6}
list2: {1,4,null,null}
list3: {null,null,null,6}

由于的ArrayList的数量是先验未知的,我想用递归。不过,也许有可能是简单的解决方案?

Since the number of arraylists is apriori unknown, I thought to use recursion. However, perhaps there might be simpler solutions?

推荐答案

听起来像是你可能想使用谷歌的优秀的番石榴库的。查看集合类

Sounds like you might want to use Google's excellent guava-libraries. Check out the Sets class.

这篇关于多的ArrayList逻辑合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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