Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /** * the intersection of two collections. * * @param c1 * collection1. * @param c2 * collection2. * @return the intersection, i.e. all elements that are in both collections. * @since 0.1 */ public static Collection intersection(final Collection c1, final Collection c2) { final List list = new ArrayList(); final Object[] members_c1 = c1.toArray(); for (int i = 0; i < members_c1.length; i++) { if (c2.contains(members_c1[i])) { list.add(members_c1[i]); } } return list; } }