Java Utililty Methods Collection Equal

List of utility methods to do Collection Equal

Description

The list of methods to do Collection Equal are organized into topic(s).

Method

booleanequals(Iterable collection1, Iterable collection2)
Returns true if the elements of the two given Collection s are equal and have the same order
boolean retval = false;
if (collection1 != null && collection2 != null) {
    Iterator<?> iteratorOther = collection2.iterator();
    Iterator<?> iteratorThis = collection1.iterator();
    retval = true;
    while (iteratorOther.hasNext() && iteratorThis.hasNext()) {
        Object elementOther = iteratorOther.next();
        Object elementThis = iteratorThis.next();
...
booleanequalsAny(Object object, Collection objects)
Checks whether object equals any of objects , using the Object#equals(Object) method in object for comparisons.
for (Object o : objects) {
    if (object == null && o == null) {
        return true;
    } else if (object != null && object.equals(o)) {
        return true;
return false;
...
booleanequalsCollectionsAnyOrder(Collection i1, Collection i2)
Check if values in iterables are identical (in any order) This method check sizes first For first collection calls Iterable#iterator() only once, and several times for second collection (max = size of collection)
if (i1 == i2) {
    return true;
if (i1 == null) {
    if (i2 == null) {
        return true;
    return false;
...
BooleanequalsNull(Collection collection)
equals Null
return collection == null;
booleanequalsOne(final T o1, final Collection others)
equals One
for (final Object o : others) {
    if (o.equals(o1)) {
        return true;
return false;
booleanequalsSet(Collection c1, Collection c2)
equals Set
boolean equals;
if (c1 == null) {
    equals = (c2 == null);
} else if (c2 == null) {
    equals = false;
} else if (c1.size() == c2.size()) {
    equals = true;
    Iterator iterC1 = c1.iterator();
...
booleanequalsSet(Collection c1, Collection c2)
equals Set
return new HashSet(c1).equals(new HashSet(c2));
booleanequalsUnordered(Collection collection1, Collection collection2)
Tests, if the two collection have the same elements.
boolean retval = collection1.size() == collection2.size();
for (Object iObject : collection1) {
    retval &= collection2.contains(iObject);
return retval;
booleanequalsUnordered(Collection collection1, Collection collection2)
equals Unordered
return collection1 == collection2
        || (collection1.size() == collection2.size() && collection1.containsAll(collection2));
booleanequalsUnorderedCollections(Collection a, Collection b)
Compares the elements of two collections using Object.equals on the elements.
if (a == b) {
    return true;
if (a.size() != b.size())
    return false;
List<T> _b = new ArrayList<T>(b);
for (final T elemA : a) {
    boolean foundMatching = false;
...