Here you can find the source of intersection(Collection a, Collection b)
public static Collection intersection(Collection a, Collection b)
//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) {/*from ww w. j a va 2 s . co m*/ Collection results = new HashSet(); for (Iterator i = a.iterator(); i.hasNext();) { Object o = i.next(); if (b.contains(o)) { results.add(o); } } return results; } }