Here you can find the source of subtract(Collection
public static List<Integer> subtract(Collection<Integer> a, Collection<Integer> b)
//package com.java2s; /******************************************************************************* * Copyright SemanticBits, Northwestern University and Akaza Research * //w w w.jav a 2s. c om * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/caaers/LICENSE.txt for details. ******************************************************************************/ import java.util.*; public class Main { public static List<Integer> subtract(Collection<Integer> a, Collection<Integer> b) { Set<Integer> y = new HashSet<Integer>(b); Set<Integer> z = new HashSet<Integer>(); for (Integer i : a) { if (y.add(i)) z.add(i); } return new ArrayList(z); } }