Java tutorial
//package com.java2s; import java.util.Collection; import java.util.HashSet; import java.util.Set; public class Main { public static <K> Set<K> intersect(Collection<K> a, Collection<K> b) { Set<K> ret = new HashSet<K>(); for (K v : a) { if (b.contains(v)) ret.add(v); } return ret; } }