Logical conjunction for multiple arraylists

ε祈祈猫儿з 提交于 2019-12-25 12:49:19

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/8748931/logical-conjunction-for-multiple-arraylists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!