Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Main { public static <T> Set<T> intersection(Collection<? extends T> c1, Collection<? extends T> c2) { Set<T> result = new HashSet<T>(); for (Iterator<? extends T> it = c1.iterator(); it.hasNext();) { T element = it.next(); if (c2.contains(element)) result.add(element); } return result; } }