Java Collection Equal equals(Collection collection1, Collection collection2)

Here you can find the source of equals(Collection collection1, Collection collection2)

Description

equals

License

Open Source License

Declaration

public static boolean equals(Collection<?> collection1, Collection<?> collection2) 

Method Source Code

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

import java.util.Collection;

import java.util.Iterator;

public class Main {
    public static boolean equals(Collection<?> collection1, Collection<?> collection2) {
        if (collection1 == collection2) {
            return true;
        }/* www  .  j a v  a 2 s.  c o m*/

        if (collection1.size() != collection2.size()) {
            return false;
        }

        final Iterator<?> iterator1 = collection1.iterator();
        final Iterator<?> iterator2 = collection2.iterator();

        while (iterator1.hasNext()) {
            final Object object1 = iterator1.next();
            final Object object2 = iterator2.next();

            if ((object1 == null && object2 != null) || (object1 != null && object2 == null)) {
                return false;
            }

            if (object1 != null && !object1.equals(object2)) {
                return false;
            }
        }

        return true;
    }
}

Related

  1. equal(Collection col1, Collection col2)
  2. equalCollection(Collection c1, Collection c2)
  3. equalContent(Collection col1, Collection col2)
  4. equalContent(final Collection a, final Collection b)
  5. equals(Collection c1, Collection c2)
  6. equals(Collection collection1, Collection collection2)
  7. equals(Collection a, Collection b, boolean ordered)
  8. equals(final Collection c1, final Collection c2)
  9. equals(Iterable collection1, Iterable collection2)