Here you can find the source of subtract(Collection firstCollection, Collection secondCollection)
public static Collection subtract(Collection firstCollection, Collection secondCollection)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collection; public class Main { public static Collection subtract(Collection firstCollection, Collection secondCollection) { Collection collection = new ArrayList<>(); for (Object object : firstCollection) { if (!secondCollection.contains(object)) { collection.add(object);// w w w. ja v a 2 s . co m } } return collection; } }