Java Collection Intersect intersectCollections(Collection collection1, Collection collection2)

Here you can find the source of intersectCollections(Collection collection1, Collection collection2)

Description

Returns all items that are both in collection1 and in collection2

License

Open Source License

Declaration

public static <T> Collection<T> intersectCollections(Collection<? extends T> collection1,
        Collection<? extends T> collection2) 

Method Source Code


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

Related

  1. intersect(Collection... collections)
  2. intersect(Collection a, Collection b)
  3. intersect(Collection collA, Collection collB, Collection target)
  4. intersect(Collection collection1, Collection collection2)
  5. intersect(Collection t1, Collection t2)
  6. intersectingCollections(Collection collection1, Collection collection2)
  7. intersectInto(C into, Collection... from)
  8. intersection( Collection> coll)
  9. intersection(Collection a, Collection b)