Java List Compare compare(List list1, List list2)

Here you can find the source of compare(List list1, List list2)

Description

Verifies that list2 contains the items of list1 and returns the list of the items from list1 that don't belong to list2

License

Apache License

Declaration

public static List<Integer> compare(List<Integer> list1, List<Integer> list2) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*from   w w w .  ja  v  a  2 s .  com*/
     * Verifies that list2 contains the items of list1 and returns the list of the items from list1 that don't belong to list2
     */
    public static List<Integer> compare(List<Integer> list1, List<Integer> list2) {
        List<Integer> badList = new ArrayList<Integer>();

        for (Integer i : list1) {
            if (!list2.contains(i)) {
                badList.add(i);
            }
        }
        return badList;
    }
}

Related

  1. canonicalCompare(List o1, List o2, Comparator elemComparator)
  2. compare(List lhs, Collection rhs, List standard)
  3. compare(List> beanList1, List> beanList2, final int[] sortKeys, final boolean[] sortAscending, final boolean nullAlwaysFirst, final int naOrder)
  4. compare(List a, List b)
  5. compare(List strList1, List strList2)
  6. compare(List a, List b)
  7. compare(String str, List list)