Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; public class Main { /** * Returns all items that are both in collection1 and in collection2 */ public static <T> Collection<T> intersectCollections(Collection<? extends T> collection1, Collection<? extends T> collection2) { Collection<T> result = new ArrayList<T>(collection1); result.retainAll(collection2); return result; } }