Java tutorial
//package com.java2s; import java.util.Collection; import java.util.HashSet; import java.util.Set; public class Main { /** * Returns the intersection of the given Collections. * * @param c1 the first Collection. * @param c2 the second Collection. * @param <T> the type. * @return the intersection of the Collections. */ public static <T> Collection<T> intersection(Collection<T> c1, Collection<T> c2) { Set<T> set1 = new HashSet<>(c1); set1.retainAll(new HashSet<>(c2)); return set1; } }