Java Set Intersect intersectsWith(final Set a, final Set b)

Here you can find the source of intersectsWith(final Set a, final Set b)

Description

intersects With

License

Open Source License

Declaration

public static <T> boolean intersectsWith(final Set<? extends T> a, final Set<? extends T> b) 

Method Source Code


//package com.java2s;

import java.util.Iterator;
import java.util.Set;

public class Main {
    public static <T> boolean intersectsWith(final Set<? extends T> a, final Set<? extends T> b) {
        if (a == b) {
            return true;
        }/*from ww w. ja v a2 s .  com*/
        final Set/*<T>*/ lSet, sSet;
        if (a.size() >= b.size()) {
            lSet = a;
            sSet = b;
        } else {
            lSet = b;
            sSet = a;
        }
        for (Iterator i = sSet.iterator(); i.hasNext();) {
            Object item = i.next();
            if (lSet.contains(item)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. intersection(Set setA, Set setB)
  2. intersection(Set setA, Set setB)
  3. intersectionP(Set s1, Set s2)
  4. intersects(Set set1, Set set2)
  5. intersectSet(Set orig, Set intersect)
  6. intersectTwoSets(Set a, Set b)