Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Set; public class Main { public static <E> boolean areDisjoint(Set<E> setOne, Set<E> setTwo) { if (setOne == null || setTwo == null) { return true; } Set<E> smallerSet = setOne; Set<E> largerSet = setTwo; if (setOne.size() > setTwo.size()) { smallerSet = setTwo; largerSet = setOne; } for (E el : smallerSet) { if (largerSet.contains(el)) { return false; } } return true; } }