问题描述
限时送ChatGPT账号..有多个arraylists(arraylists的数量是先验未知的).在每个数组列表中,我需要找到一个元素,该元素提供与来自其他列表的元素的逻辑连接.请注意,仅对非空值进行比较.
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}
由于数组列表的数量是先验未知的,所以我想使用递归.但是,也许有更简单的解决方案?
Since the number of arraylists is apriori unknown, I thought to use recursion. However, perhaps there might be simpler solutions?
推荐答案
听起来您可能想要使用 Google 出色的 番石榴库.查看集合类.
Sounds like you might want to use Google's excellent guava-libraries. Check out the Sets class.
这篇关于多个数组列表的逻辑连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论