Here you can find the source of intersection(final Collection c1, final Collection c2)
Parameter | Description |
---|---|
c1 | collection1. |
c2 | collection2. |
public static Collection intersection(final Collection c1, final Collection c2)
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /**/*from w ww. j a v a 2s .co m*/ * 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; } }