Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { /** * Compares two collections returning the number of elements they have in common * * @param <T> * @param one * @param two * @return */ public static <T> int collectionCompare(Collection<T> one, Collection<T> two) { int count = 0; Iterator<T> e = one.iterator(); while (e.hasNext()) { if (two.contains(e.next())) ++count; } return count; } }