问题
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