Here you can find the source of difference(Set
static public <T> Set<T> difference(Set<T> s1, Set<T> s2)
//package com.java2s; import java.util.*; public class Main { /** Return is s1 \ s2 */ //from w w w . ja v a 2 s. c om static public <T> Set<T> difference(Set<T> s1, Set<T> s2) { Set<T> s3 = new HashSet<T>(s1); s3.removeAll(s2); return s3; } }