Java Collection Minus minus(Collection toBeDeletedFrom, Collection tobeDeleted)

Here you can find the source of minus(Collection toBeDeletedFrom, Collection tobeDeleted)

Description

minus

License

BSD License

Declaration

public static Collection minus(Collection toBeDeletedFrom, Collection tobeDeleted) 

Method Source Code


//package com.java2s;
/*L// w  ww  . j a v  a  2  s .  c  o  m
 *  Copyright Ekagra Software Technologies Ltd.
 *  Copyright SAIC, SAIC-Frederick
 *
 *  Distributed under the OSI-approved BSD 3-Clause License.
 *  See http://ncip.github.com/common-security-module/LICENSE.txt for details.
 */

import java.util.*;

public class Main {
    public static Collection minus(Collection toBeDeletedFrom, Collection tobeDeleted) {
        ArrayList result = new ArrayList(toBeDeletedFrom);

        Iterator it = tobeDeleted.iterator();
        while (it.hasNext()) {
            Object oj = it.next();
            if (toBeDeletedFrom.contains(oj)) {
                result.remove(oj);
            }
        }

        return result;
    }
}

Related

  1. minus(Collection c1, Collection c2)
  2. minus(Collection src, Collection ref)