Here you can find the source of intersect(Collection
Parameter | Description |
---|---|
T | a parameter |
collA | a parameter |
collB | a parameter |
target | a collection that will be returned by this method. It will be cleared by this method before inserting the required elements. |
public static <T> Collection<T> intersect(Collection<T> collA, Collection<T> collB, Collection<T> target)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /**//from w w w .j av a2 s .com * return a new Collection with the elements which appear both in a and b.<BR> * <B>Complexity:</B> for sets - linear, for lists - quadratic. * * @param <T> * @param collA * @param collB * @param target a collection that will be returned by this method. It will be cleared by this method before inserting the required elements. * @return a new Collection with the elements which appear both in a and b */ public static <T> Collection<T> intersect(Collection<T> collA, Collection<T> collB, Collection<T> target) { target.clear(); for (T elem : collA) { if (collB.contains(elem)) { target.add(elem); } } return target; } }