Here you can find the source of diffSet(List
Parameter | Description |
---|---|
a | a parameter |
b | a parameter |
T | a parameter |
public static <T> List<T> diffSet(List<T> a, List<T> b)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { /**i/* w ww . j av a 2s . c o m*/ * a - b * @param a * @param b * @param <T> * @return */ public static <T> List<T> diffSet(List<T> a, List<T> b) { List<T> c = new ArrayList<T>(); Map<T, T> map = new HashMap<T, T>(); for (T t : b) { map.put(t, t); } for (T t : a) { if (map.get(t) == null) c.add(t); } return c; } }