0
List x=new ArrayList<ArrayList<String>;
x.add(new ArrayList(Arrays.asList("1","2","3","4")));
x.add(new ArrayList(Arrays.asList("3","4")));
x.add(new ArrayList(Arrays.asList("4","5")));

Need to find intersection of all the list inside the list. Cant do manually as number of list inside the list varies.

suba
  • 65
  • 1
  • 7

1 Answers1

1

Can try:

List<String> result = (ArrayList<String>) x.get(0);
for (int i = 1; i < x.size(); i++) {
    result.retainAll((ArrayList<String>) x.get(i));
}
return result;
hoan
  • 1,058
  • 8
  • 13