Here you can find the source of minus(Collection
Parameter | Description |
---|---|
T | a parameter |
primaryCollection | a parameter |
toBeRemovedCollection | a parameter |
target | a collection that will be returned by this method. I will be cleared by this method before inserting the required elements. |
public static <T> Collection<T> minus(Collection<T> primaryCollection, Collection<T> toBeRemovedCollection, Collection<T> target)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /**//from ww w. j a v a2 s . com * Return a new Collection containing the elements of Collection a minus elements of Collection b * @param <T> * @param primaryCollection * @param toBeRemovedCollection * @param target a collection that will be returned by this method. I will be cleared by this method before inserting the required elements. * @return a new Collection containing the elements of Collection a minus elements of Collection b */ public static <T> Collection<T> minus(Collection<T> primaryCollection, Collection<T> toBeRemovedCollection, Collection<T> target) { target.clear(); for (T elem : primaryCollection) { if (!toBeRemovedCollection.contains(elem)) { target.add(elem); } } return target; } }