Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

intersection for multiple lists

807569Aug 7 2006 — edited Aug 7 2006
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 4 2006
Added on Aug 7 2006
6 comments
1,062 views