Java Collection Equal isEquals(Collection set1, Collection set2)

Here you can find the source of isEquals(Collection set1, Collection set2)

Description

is Equals

License

Open Source License

Parameter

Parameter Description
set1 a parameter
set2 a parameter

Return

true: Set1 has the same elements of Set2

Declaration

public static <E> boolean isEquals(Collection<E> set1, Collection<E> set2) 

Method Source Code

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

import java.util.Collection;

public class Main {
    /**/*from  ww  w. j  a v  a  2  s  . c om*/
     * @param set1
     * @param set2
     * @return true: Set1 has the same elements of Set2
     */
    public static <E> boolean isEquals(Collection<E> set1, Collection<E> set2) {

        if (set1.size() == set2.size()) {
            return isSubset(set1, set2);
        }

        return false;

    }

    /**
     * Verify if a set is subset of other set
     * 
     * @param subSet
     * @param superSet
     * @return
     */
    public static <E> boolean isSubset(Collection<E> subSet, Collection<E> superSet) {
        int occurrenceCount = 0;
        if (subSet != null && superSet != null) {
            for (E subSetElement : subSet) {
                if (superSet.contains(subSetElement)) {
                    occurrenceCount++;
                }
            }
            if (occurrenceCount == subSet.size()) {
                return true;
            }
        }

        return false;

    }
}

Related

  1. isEqual(Collection a, Collection b)
  2. isEqualBasicCol(Collection col1, Collection col2)
  3. isEqualCollection(final Collection a, final Collection b)
  4. isEqualCollection(final Collection a, final Collection b)
  5. isEqualDeep(Collection a, Collection b)
  6. isEqualsSize(Collection res, Collection des)
  7. orderedEqual(Collection c1, Collection c2)