Java Collection Intersect intersection(final Collection c1, final Collection c2)

Here you can find the source of intersection(final Collection c1, final Collection c2)

Description

the intersection of two collections.

License

Open Source License

Parameter

Parameter Description
c1 collection1.
c2 collection2.

Return

the intersection, i.e. all elements that are in both collections.

Declaration

public static Collection intersection(final Collection c1,
        final Collection c2) 

Method Source Code

//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;
    }
}

Related

  1. intersection(Collection a, Collection b)
  2. intersection(Collection a, Collection b)
  3. intersection(Collection a, Collection b)
  4. intersection(Collection values1, Collection values2)
  5. intersection(final Collection a, final Collection b)
  6. intersection(final Collection a, final Collection b)
  7. intersection(final Collection c1, final Collection c2)
  8. intersectionSize(Collection c1, Collection c2)
  9. intersects(Collection c1, Collection c2)