Java List Equal isEqual(List list1, List list2)

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

Description

Checks if the given list are equals, this means that they contain the same elements.

License

Open Source License

Parameter

Parameter Description
list1 The first list.
list2 The second list.

Return

True, if both lists contain the same elements, false otherwise.

Declaration

public static boolean isEqual(List<? extends Object> list1, List<? extends Object> list2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/* w  ww . j a v  a 2  s. c  o m*/
     * Checks if the given list are equals, this means that they contain the
     * same elements.
     * 
     * @param list1 The first list.
     * @param list2 The second list.
     * 
     * @return True, if both lists contain the same elements, false otherwise.
     */
    public static boolean isEqual(List<? extends Object> list1, List<? extends Object> list2) {
        /*
         * TODO check if this is actual not the default implementation of java for equals
         */
        if (list1.size() != list2.size()) {
            return false;
        }

        for (Iterator<? extends Object> it = list1.iterator(); it.hasNext();) {
            Object obj = it.next();
            if (!list2.contains(obj)) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. equals(List list1, List list2)
  2. equalsAny(String toMatch, List matchesAny)
  3. equalsBasedOnEntryIdentity(final List a, final List b)
  4. equalShallow(List list0, List list1)
  5. isEqual(Collection listA, Collection listB)
  6. isEqual(List from, List to)
  7. isEqualAsMultiset(List left, List right)
  8. isEqualIgnoringOrder(List left, List right)
  9. isEqualList(List list1, List list2)