Here you can find the source of intersect(Collection firstSet, Collection secondSet)
public static Collection intersect(Collection firstSet, Collection secondSet)
//package com.java2s; /*L/*from w ww. j a v a 2 s . co m*/ * Copyright Ekagra Software Technologies Ltd. * Copyright SAIC, SAIC-Frederick * * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/common-security-module/LICENSE.txt for details. */ import java.util.*; public class Main { public static Collection intersect(Collection firstSet, Collection secondSet) { ArrayList result = new ArrayList(); Iterator it = firstSet.iterator(); while (it.hasNext()) { Object oj = it.next(); if (secondSet.contains(oj)) { result.add(oj); } } return result; } }