Here you can find the source of subtract(Collection a, Collection b)
public static Collection subtract(Collection a, Collection b)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.HashSet; import java.util.Iterator; public class Main { public static Collection subtract(Collection a, Collection b) {/*from w ww . j a v a 2 s . c o m*/ Collection results = new HashSet(); for (Iterator i = a.iterator(); i.hasNext();) { Object o = i.next(); if (!(b.contains(o))) { results.add(o); } } return results; } }