Computes the list of items in A that aren't in B. - Java java.util

Java examples for java.util:List Operation

Description

Computes the list of items in A that aren't in B.

Demo Code


import java.util.List;
import java.util.Map;

public class Main{
    public static void main(String[] argv){
        List a = java.util.Arrays.asList("asdf","java2s.com");
        List b = java.util.Arrays.asList("asdf","java2s.com");
        System.out.println(removedBasedOnEntryIdentity(a,b));
    }/*from ww w.j  a  v  a  2  s  . c  o m*/
    /**
     * Computes the list of items in A that aren't in B.
     */

    public static <T> List<T> removedBasedOnEntryIdentity(
            final List<? extends T> a, final List<? extends T> b) {
        final ListFactory<T> result = ListFactory.start();

        for (T obj : a) {
            if (!containsBasedOnEntryIdentity(b, obj)) {
                result.add(obj);
            }
        }

        return result.result();
    }
    public static boolean containsBasedOnEntryIdentity(final List<?> list,
            final Object object) {
        for (Object obj : list) {
            if (obj == object) {
                return true;
            }
        }

        return false;
    }
}

Related Tutorials