Here you can find the source of intersects(Set
public static <T> boolean intersects(Set<T> set1, Set<T> set2)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static <T> boolean intersects(Set<T> set1, Set<T> set2) { if (set1.size() > set2.size()) return intersects(set2, set1); for (T x : set1) if (set2.contains(x)) return true; return false; }//from ww w . j a va 2s . c o m }