Java tutorial
//package com.java2s; import java.util.*; public class Main { /** * Returns true if there is any element that is common to both collections. */ public static boolean containsAny(Collection c1, Collection c2) { // A better implementation here would be to use sets Collection smallCollection; Collection largeCollection; if (c1.size() < c2.size()) { smallCollection = c1; largeCollection = c2; } else { smallCollection = c2; largeCollection = c1; } boolean intersect = false; Iterator i = smallCollection.iterator(); while (i.hasNext()) { if (largeCollection.contains(i.next())) { intersect = true; break; } } return intersect; } }