Here you can find the source of containsAny(Collection c1, Collection c2)
public static boolean containsAny(Collection c1, Collection c2)
//package com.java2s; import java.util.*; public class Main { /**// w w w .java 2 s. co m * 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; } }