Here you can find the source of difference(Set
public static <T> Set<T> difference(Set<T> first, Set<T> second)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static <T> Set<T> difference(Set<T> first, Set<T> second) { Set<T> copyOfFirst = new LinkedHashSet<>(first); copyOfFirst.removeAll(second);/*from w w w .ja v a 2 s . c om*/ return copyOfFirst; } }