Java List Equal equalLists(List aV1, List aV2)

Here you can find the source of equalLists(List aV1, List aV2)

Description

compares two List instances.

License

Open Source License

Parameter

Parameter Description
aV1 First List instance to compare.
aV2 Second List instance to compare.

Return

true if List's are equal; false otherwise.

Declaration

public static boolean equalLists(List aV1, List aV2) 

Method Source Code

//package com.java2s;
/***********************************************************
 Copyright (C) 2004 VeriSign, Inc./* w  w  w .ja v a 2s  .co m*/
    
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
    
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.
    
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    
 http://www.verisign.com/nds/naming/namestore/techdocs.html
 ***********************************************************/

import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * compares two <code>List</code> instances. The Java 1.1 <code>List</code>
     * class does not implement the <code>equals</code> methods, so
     * <code>equalLists</code> was written to implement <code>equals</code> of
     * two <code>Lists</code> (aV1 and aV2). This method is not need for Java 2.
     * 
     * @param aV1
     *            First List instance to compare.
     * @param aV2
     *            Second List instance to compare.
     * @return <code>true</code> if List's are equal; <code>false</code>
     *         otherwise.
     */
    public static boolean equalLists(List aV1, List aV2) {
        if ((aV1 == null) && (aV2 == null)) {
            return true;
        }

        else if ((aV1 != null) && (aV2 != null)) {
            if (aV1.size() != aV2.size()) {
                return false;
            }

            Iterator v1Iter = aV1.iterator();
            Iterator v2Iter = aV2.iterator();

            for (int i = 0; i < aV1.size(); i++) {
                Object elm1 = v1Iter.next();
                Object elm2 = v2Iter.next();

                if (!((elm1 == null) ? (elm2 == null) : elm1.equals(elm2))) {
                    return false;
                }
            }

            return true;
        } else {
            return false;
        }
    }
}

Related

  1. areEqualConsideringOrder(List listA, List listB)
  2. equal(List coll, List otherColl)
  3. equal(List objects)
  4. equal(List v1, List v2)
  5. equalLists(List a, List b)
  6. equalLists(List list1, List list2)
  7. equalLists(List list1, List list2)
  8. equalLists(List one, List two)
  9. equalLists(List a, List b)