Java Collection Equal equals(final Collection c1, final Collection c2)

Here you can find the source of equals(final Collection c1, final Collection c2)

Description

true if for each a in c1, a exists in c2, and if for each b in c2, b exist in c1 and c1 and c2 are the same size.

License

Open Source License

Declaration

public static <T> boolean equals(final Collection<T> c1, final Collection<T> c2) 

Method Source Code

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

import java.util.Collection;

public class Main {
    /**/*www . jav  a 2s  . co  m*/
     * true if for each a in c1, a exists in c2,
     * and if for each b in c2, b exist in c1
     * and c1 and c2 are the same size.
     * Note that (a,a,b) (a,b,b) are equal.
     */
    public static <T> boolean equals(final Collection<T> c1, final Collection<T> c2) {
        if (c1 == null || c2 == null) {
            return c1 == c2;
        }
        if (c1.size() != c2.size()) {
            return false;
        }
        if (c1 == c2) {
            return true;
        }
        if (!c1.containsAll(c2)) {
            return false;
        }
        return c2.containsAll(c1);
    }
}

Related

  1. equalContent(final Collection a, final Collection b)
  2. equals(Collection c1, Collection c2)
  3. equals(Collection collection1, Collection collection2)
  4. equals(Collection collection1, Collection collection2)
  5. equals(Collection a, Collection b, boolean ordered)
  6. equals(Iterable collection1, Iterable collection2)
  7. equalsAny(Object object, Collection objects)
  8. equalsCollectionsAnyOrder(Collection i1, Collection i2)
  9. equalsNull(Collection collection)

  10. HOME | Copyright © www.java2s.com 2016