Java Utililty Methods List Compare

List of utility methods to do List Compare

Description

The list of methods to do List Compare are organized into topic(s).

Method

intcanonicalCompare(List o1, List o2, Comparator elemComparator)
Compares two List s with respect to canonical ordering.
int siz1 = o1.size(), siz2 = o2.size();
if (siz1 != siz2) {
    return siz1 - siz2;
return lexCompare(o1, o2, elemComparator);
intcompare(List lhs, Collection rhs, List standard)
Compare two Collections by reference to a standard List.
int result = compare(lhs, rhs);
if (result == Integer.MAX_VALUE) {
    if (null == standard) {
        result = compare(lhs, rhs, lhs); 
    } else {
        boolean leftHasThem = lhs.containsAll(standard);
        boolean rightHasThem = rhs.containsAll(standard);
        if (leftHasThem != rightHasThem) {
...
intcompare(List> beanList1, List> beanList2, final int[] sortKeys, final boolean[] sortAscending, final boolean nullAlwaysFirst, final int naOrder)
compare
int comp = EQUAL;
for (int i = 0; i < sortKeys.length; i++) {
    if (sortKeys[i] < 0) {
        continue;
    boolean asc = true;
    try {
        asc = sortAscending[i];
...
Listcompare(List list1, List list2)
Verifies that list2 contains the items of list1 and returns the list of the items from list1 that don't belong to list2
List<Integer> badList = new ArrayList<Integer>();
for (Integer i : list1) {
    if (!list2.contains(i)) {
        badList.add(i);
return badList;
intcompare(List a, List b)
compare
if (a.size() == 0 || b.size() == 0) {
    return 0;
if (a.size() <= b.size()) {
    for (String x : a) {
        boolean z = false;
        for (String y : b) {
            if (x.equals(y)) {
...
booleancompare(List strList1, List strList2)
Compare this two list whether equal
List<String> list1 = strList1 == null ? new ArrayList<String>() : strList1;
List<String> list2 = strList2 == null ? new ArrayList<String>() : strList2;
if (list1.size() != list2.size()) {
    return false;
for (String str1 : list1) {
    boolean isFound = false;
    int index = 0;
...
booleancompare(List a, List b)
compare
if (a.size() != b.size())
    return false;
Collections.sort(a);
Collections.sort(b);
for (int i = 0; i < a.size(); i++) {
    if (!a.get(i).equals(b.get(i)))
        return false;
return true;
booleancompare(String str, List list)
compare
String x = str.replace(" ", "");
x = x.replace("[", "").replace("]", "");
String y = list.toString().replace(" ", "");
y = y.replace("[", "").replace("]", "");
return x.equals(y);
intcompareByList(List list, T a, T b)
Compare two items, with the ordering determined by a list of those items.
if (a == null) {
    if (b == null) {
        return 0;
    } else {
        return -1;
} else {
    if (b == null) {
...
StringcompareFileLists(List expected, List gotten)
compare File Lists
StringBuilder sb = new StringBuilder(
        "Expected (" + expected.size() + "): \t\t Gotten (" + gotten.size() + "):\n");
List<String> notFound = new ArrayList<>();
for (String s : expected) {
    if (gotten.contains(s))
        sb.append(s + "\t\t" + s + "\n");
    else
        notFound.add(s);
...