Here you can find the source of diffAsSet(Collection
Parameter | Description |
---|---|
T | Type of items in the collection |
list1 | First collection |
list2 | Second collection |
public static <T> Set<T> diffAsSet(Collection<T> list1, Collection<T> list2)
//package com.java2s; import java.util.*; public class Main { /**//w w w . jav a 2 s . c om * Returns all objects in list1 that are not in list2. * * @param <T> Type of items in the collection * @param list1 First collection * @param list2 Second collection * @return The collection difference list1 - list2 */ public static <T> Set<T> diffAsSet(Collection<T> list1, Collection<T> list2) { Set<T> diff = new HashSet<>(); for (T t : list1) { if (!list2.contains(t)) { diff.add(t); } } return diff; } }