Java Collection Subset isSubset(Collection subSet, Collection superSet)

Here you can find the source of isSubset(Collection subSet, Collection superSet)

Description

Verify if a set is subset of other set

License

Open Source License

Parameter

Parameter Description
subSet a parameter
superSet a parameter

Declaration

public static <E> boolean isSubset(Collection<E> subSet, Collection<E> superSet) 

Method Source Code

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

import java.util.Collection;

public class Main {
    /**//  w ww . j  a  v  a2s  .c o m
     * 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. isSubset(Collection subset, Collection of)
  2. isSubset(Collection s1, Collection s2)
  3. isSubset(Collection subset, Collection superset)
  4. isSubset(final Collection l1, final Collection l2)
  5. sub(Collection list, int start, int end)