Java tutorial
//package com.java2s; //License from project: Apache License import java.util.LinkedList; import java.util.List; import com.google.common.base.Equivalence; import com.google.common.collect.Iterables; public class Main { /** * <strong>WARNING:</strong> very low efficiency (O(N*N)) * @return A list containing the elements of source that are not in filter, using <code>equivalence</code> to distinguish different elements. */ public static <T> List<T> difference(Iterable<? extends T> source, Iterable<? extends T> filter, Equivalence<? super T> equivalence) { final List<T> result = new LinkedList<T>(); if (source != null && filter != null) { sourceLoop: for (T sourceElement : source) { for (T filterElement : filter) { if (equivalence.equivalent(sourceElement, filterElement)) { continue sourceLoop; } } result.add(sourceElement); } } else if (source != null && filter == null) { Iterables.addAll(result, source); } return result; } }