Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;
import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**
     * Subtract objects in collection b from collection a. The string value
     * of the object is used for comparisons.
     * 
     * @param a a collection that will have members removed
     * @param b a collection whose objects will be removed from a
     * @return a new collection that contains the remaining objects in a
     */
    public static Collection subtractByString(Collection a, Collection b) {
        Collection retColl = new ArrayList();
        Object obj = null;
        Iterator it = a.iterator();
        while (it.hasNext()) {
            obj = it.next();
            if (!b.contains(obj)) {
                retColl.add(obj);
            }
        }
        return retColl;
    }
}