Here you can find the source of intersectsWith(final Set extends T> a, final Set extends T> b)
public static <T> boolean intersectsWith(final Set<? extends T> a, final Set<? extends T> b)
//package com.java2s; import java.util.Iterator; import java.util.Set; public class Main { public static <T> boolean intersectsWith(final Set<? extends T> a, final Set<? extends T> b) { if (a == b) { return true; }/*from ww w. ja v a2 s . com*/ final Set/*<T>*/ lSet, sSet; if (a.size() >= b.size()) { lSet = a; sSet = b; } else { lSet = b; sSet = a; } for (Iterator i = sSet.iterator(); i.hasNext();) { Object item = i.next(); if (lSet.contains(item)) { return true; } } return false; } }