Here you can find the source of difference(final Collection
public static <T> List<T> difference(final Collection<T> c1, final Collection<T> c2)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /**//from w w w . j a v a 2s . c om * Returns a such that a exists in c1 but not in c2. * Always returns a new collection. */ public static <T> List<T> difference(final Collection<T> c1, final Collection<T> c2) { if (c1 == null || c1.size() == 0) { return new ArrayList<>(0); } if (c2 == null || c2.size() == 0) { return new ArrayList<>(c1); } final List<T> difference = new ArrayList<>(); for (final T current : c1) { if (!c2.contains(current)) { difference.add(current); } } return difference; } }