Java tutorial
//package com.java2s; //License from project: Apache License import java.util.LinkedList; import java.util.List; import com.google.common.base.Equivalence; public class Main { /** * <strong>WARNING:</strong> very low efficiency (O(N*N)) * @return A list containing the elements of source that are also in filter, using <code>equivalence</code> to distinguish different elements. */ public static <T> List<T> intersection(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)) { result.add(sourceElement); continue sourceLoop; } } } } return result; } }