Here you can find the source of difference(Collection
public static <E> Collection<E> difference(Collection<E> set1, Collection<E> set2)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static <E> Collection<E> difference(Collection<E> set1, Collection<E> set2) { List<E> differenceCopy = new ArrayList<E>(); differenceCopy.addAll(set1);//from w w w. java2s. c o m differenceCopy.removeAll(set2); return differenceCopy; } }