public static boolean hasIntersection(final Collection a, final Collection b) {
        if (a.size() < 50 && b.size() < 50) {
            Iterator it = a.iterator();
            while(it.hasNext())
                if (b.contains(it.next()))
                    return true;
        }
        else if (a.size() < b.size()) {
            HashSet bSet = new HashSet(b);
            Iterator it = a.iterator();
            while(it.hasNext())
                if (bSet.contains(it.next()))
                    return true;
        }
        else {
            HashSet aSet = new HashSet(a);
            Iterator it = b.iterator();
            while(it.hasNext())
                if (aSet.contains(it.next()))
                    return true;
        }
        return false;
    }