Java Utililty Methods Collection Subset

List of utility methods to do Collection Subset

Description

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

Method

booleanisSubset(Collection subset, Collection of)
is Subset
for (Object obj : subset) {
    if (!of.contains(obj)) {
        return false;
return true;
booleanisSubset(Collection subSet, Collection superSet)
Verify if a set is subset of other set
int occurrenceCount = 0;
if (subSet != null && superSet != null) {
    for (E subSetElement : subSet) {
        if (superSet.contains(subSetElement)) {
            occurrenceCount++;
    if (occurrenceCount == subSet.size()) {
...
booleanisSubset(Collection s1, Collection s2)
is Subset
for (T t : s2) {
    if (!s1.contains(t))
        return false;
return true;
booleanisSubset(Collection subset, Collection superset)
is Subset
if ((superset == null) || (superset.size() == 0)) {
    return ((subset == null) || (subset.size() == 0));
HashSet<T> hash = new HashSet<T>(superset);
for (T t : subset) {
    if (!hash.contains(t)) {
        return false;
return true;
booleanisSubset(final Collection l1, final Collection l2)
Checks whether the first collection provided is a subset of the second collection provided.
return l2.containsAll(l1);
Listsub(Collection list, int start, int end)
sub
if (list == null || list.isEmpty()) {
    return null;
return sub(new ArrayList<T>(list), start, end);