Java List Compare compareLists(List l1, List l2)

Here you can find the source of compareLists(List l1, List l2)

Description

compare Lists

License

Open Source License

Declaration

public static <E> boolean compareLists(List<E> l1, List<E> l2) 

Method Source Code

//package com.java2s;
/*/*from   ww  w .j av  a  2  s  .c o m*/
Copyright (c) Microsoft Open Technologies, Inc.
All Rights Reserved
See License.txt in the project root for license information.
*/

import java.util.List;

public class Main {
    public static <E> boolean compareLists(List<E> l1, List<E> l2) {
        return compareArrays(l1.toArray(), l2.toArray());
    }

    public static boolean compareArrays(Object[] arr1, Object[] arr2) {
        if (arr1 == null && arr2 == null) {
            return true;
        }

        if (arr1 == null || arr2 == null) {
            return false;
        }

        if (arr1.length != arr2.length) {
            return false;
        }

        for (int i = 0; i < arr1.length; i++) {
            Object o1 = arr1[i];
            Object o2 = arr2[i];

            if (!compare(o1, o2)) {
                return false;
            }
        }
        return true;
    }

    public static boolean compare(Object o1, Object o2) {
        if (o1 == null && o2 == null) {
            return true;
        }

        if (o1 == null || o2 == null) {
            return false;
        }

        return o1.equals(o2);
    }
}

Related

  1. compareList(List listA, List listB)
  2. compareList(Object eObj, Object rObj)
  3. compareLists(Class type, List list1, List list2)
  4. compareLists(final List list1, final List list2)
  5. compareLists(List strings1, List strings2, boolean ignoreCase)
  6. compareLists(List list, List> listOfLists)
  7. compareLists(List a, List b)
  8. compareLists(List a, List b)
  9. compareLists(List list1, List list2)