Java tutorial
//package com.java2s; import java.util.Collection; import java.util.HashSet; public class Main { public static Integer getIntersectionSize(Collection<? extends Object> list1, Collection<? extends Object> list2) { return getIntersection(list1, list2).size(); } public static Collection<? extends Object> getIntersection(Collection<? extends Object> list1, Collection<? extends Object> list2) { HashSet<?> hashSet = new HashSet<Object>(list1); Collection<?> intersection = hashSet; intersection.retainAll(list2); return intersection; } }