Here you can find the source of difference(final List extends T> list1, final List extends T> list2)
public static <T> List<T> difference(final List<? extends T> list1, final List<? extends T> list2)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static <T> List<T> difference(final List<? extends T> list1, final List<? extends T> list2) { final List<T> result = new ArrayList<T>(list1); final Iterator<? extends T> iterator = list2.iterator(); while (iterator.hasNext()) { result.remove(iterator.next()); }// ww w . j ava 2 s . co m return result; } }