Java tutorial
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.List; import java.util.Set; public class Main { public static boolean intersect(Set<?> a, List<?> b) { return intersect(a, (Iterable<?>) b); } public static boolean intersect(Collection<?> a, Collection<?> b) { if (b.size() > a.size()) { Collection<?> c = a; a = b; b = c; } return intersect(a, (Iterable<?>) b); } public static boolean intersect(Collection<?> a, Iterable<?> iterable) { for (Object ele : iterable) { if (a.contains(ele)) return true; } return false; } }