Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.HashSet; import java.util.Iterator; public class Main { public static Collection intersection(Collection a, Collection b) { Collection results = new HashSet(); for (Iterator i = a.iterator(); i.hasNext();) { Object o = i.next(); if (b.contains(o)) { results.add(o); } } return results; } }