Is there a way to find common elements in multiple lists?
You can use Set's intersection method offered by Guava, Here is a little example :
public <T> Set<T> intersection(List<T>... list) {
Set<T> result = Sets.newHashSet(list[0]);
for (List<T> numbers : list) {
result = Sets.intersection(result, Sets.newHashSet(numbers));
}
return result;
}
Hope that could help you
You can transform the lists to sets, and then use Set.retainAll
method for intersection between the different sets.
Once you intersect all sets, you are left with the common elements, and you can transform the resulting set back to a list.