Here you can find the source of intersectCollections(Collection extends T> collection1, Collection extends T> collection2)
public static <T> Collection<T> intersectCollections(Collection<? extends T> collection1, Collection<? extends T> collection2)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; public class Main { /**/*from w w w. j av a2s . com*/ * 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; } }