I need to get the intersection of multiple lists and was wondering if there is a more straight forward way than creating a class that organises the intersection for added elements from different lists like:
class Intersection extends ArrayList
{
private Set checked = new HashSet();
public Intersection()
{
super();
}
public boolean add(Object o)
{
if (checked.contains(o))
{
super.add(o);
}
else
{
checked.add(o);
}
return true;
}
}
I know I could use retainAll which works fine on two different lists. But for multiple lists (>2) it seems to get a bit akward since i have to keep the original copies of each list and then intersect each list with each other.