Java List Compare compareList(List listA, List listB)

Here you can find the source of compareList(List listA, List listB)

Description

Compares two lists

License

Apache License

Parameter

Parameter Description
T The type of items in the list
listA List 1
listB List 2

Return

Returns a boolean comparing the lists

Declaration

public static <T> boolean compareList(List<T> listA, List<T> listB) 

Method Source Code

//package com.java2s;
/*/*from w  ww. j a  v a  2s  .  c  o m*/
 * Copyright 2008-2013 LinkedIn, Inc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import java.util.List;

public class Main {
    /**
     * Compares two lists
     * 
     * @param <T> The type of items in the list
     * @param listA List 1
     * @param listB List 2
     * @return Returns a boolean comparing the lists
     */
    public static <T> boolean compareList(List<T> listA, List<T> listB) {
        // Both are null.
        if (listA == null && listB == null)
            return true;

        // At least one of them is null.
        if (listA == null || listB == null)
            return false;

        // If the size is different.
        if (listA.size() != listB.size())
            return false;

        // Since size is same, containsAll will be true only if same
        return listA.containsAll(listB);
    }
}

Related

  1. compare(List a, List b)
  2. compare(String str, List list)
  3. compareByList(List list, T a, T b)
  4. compareFileLists(List expected, List gotten)
  5. compareIncarnations(List e1, List e2)
  6. compareList(Object eObj, Object rObj)
  7. compareLists(Class type, List list1, List list2)
  8. compareLists(final List list1, final List list2)
  9. compareLists(List strings1, List strings2, boolean ignoreCase)