Here you can find the source of hasIntersection(Collection extends T> s1, Collection extends T> s2)
public static <T extends Object> boolean hasIntersection(Collection<? extends T> s1, Collection<? extends T> s2)
//package com.java2s; import java.util.*; public class Main { public static <T extends Object> boolean hasIntersection(Collection<? extends T> s1, Collection<? extends T> s2) { if (s1 == null || s2 == null) return false; int n1 = s1.size(); int n2 = s2.size(); if (n2 < n1) { Collection<? extends T> t = s1; s1 = s2;//from ww w .j av a 2s. com s2 = t; } for (T e : s1) { if (s2.contains(e)) return true; } return false; } public static int size(Collection<?> c) { return (c == null) ? 0 : c.size(); } }