Java List Difference diffSet(List a, List b)

Here you can find the source of diffSet(List a, List b)

Description

i a - b

License

Apache License

Parameter

Parameter Description
a a parameter
b a parameter
T a parameter

Declaration

public static <T> List<T> diffSet(List<T> a, List<T> b) 

Method Source Code


//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;
    }
}

Related

  1. difference(List set1, List set2)
  2. differenceOfList(List a, List b)
  3. differentCategory(String prop1, String prop2, List cat1, List cat2)
  4. diffFloats(List a, List b)
  5. diffList(List aList, List bList)
  6. diffSimple(String name, Object expected, Object actual, List messages)
  7. extractDifference(List l1, List l2, List in1not2, List in2not1, List inBothFrom1, List inBothFrom2, Comparator c)
  8. formatDifferentFileNames(List results)
  9. getDiffentElement(List minList, List maxList)