Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public class Main { /** * Returns a new {@link Collection} containing <tt><i>a</i> - <i>b</i></tt>. * The cardinality of each element <i>e</i> in the returned {@link Collection} * will be the cardinality of <i>e</i> in <i>a</i> minus the cardinality * of <i>e</i> in <i>b</i>, or zero, whichever is greater. * * @param a the collection to subtract from, must not be null * @param b the collection to subtract, must not be null * @return a new collection with the results * @see Collection#removeAll */ public static Collection subtract(final Collection a, final Collection b) { ArrayList list = new ArrayList(a); for (Iterator it = b.iterator(); it.hasNext();) { list.remove(it.next()); } return list; } }