Here you can find the source of intersection(final Collection
public static <T> List<T> intersection(final Collection<T> c1, final Collection<T> c2)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /**//from w w w. j a va 2 s .c o m * return a such that a exists in c1 and a exists in c2. * always returns a new collection. */ public static <T> List<T> intersection(final Collection<T> c1, final Collection<T> c2) { if (c1 == null || c2 == null) { return new ArrayList<>(); } if (c1.size() == 0 || c2.size() == 0) { return new ArrayList<>(); } final List<T> intersection = new ArrayList<>(); for (final T current : c1) { if (c2.contains(current)) { intersection.add(current); } } return intersection; } }