Java List Equal areEqual(List list1, List list2)

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

Description

are Equal

License

Open Source License

Declaration

public static boolean areEqual(List<?> list1, List<?> list2) 

Method Source Code

//package com.java2s;
/**//www .ja va 2s .  c  om
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   IBM - Initial API and implementation
 */

import java.util.List;

public class Main {
    public static boolean areEqual(List<?> list1, List<?> list2) {
        if (list1 == null)
            return list2 == null;
        if (list2 == null)
            return false;

        int size = list1.size();
        if (size != list2.size()) {
            return false;
        }

        for (int i = 0; i < size; i++) {
            if (list1.get(i) != list2.get(i)) {
                if (list1.get(i) == null || list2.get(i) == null) {
                    return false;
                } else if (!list1.get(i).equals(list2.get(i))) {
                    return false;
                }
            }
        }

        return true;
    }
}

Related

  1. areEqual(final List list1, final List list2)
  2. areEqual(List a, List b)
  3. areEqualConsideringOrder(List listA, List listB)
  4. equal(List coll, List otherColl)
  5. equal(List objects)
  6. equal(List v1, List v2)