Java Utililty Methods Collection Intersect

List of utility methods to do Collection Intersect

Description

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

Method

CollectiongetIntersection( final Collection> collections)
get Intersection
final List<Collection<?>> collectionsList = new ArrayList<Collection<?>>(collections);
final Collection<Object> intersection = new HashSet<>();
if (collectionsList.size() != 0) {
    intersection.addAll(collectionsList.get(0));
for (int i = 1; i < collections.size() && intersection.size() > 0; i++) {
    intersection.retainAll(new HashSet<>(collectionsList.get(i)));
return intersection;
CollectiongetIntersection(Collection collection1, Collection collection2)
get Intersection
Collection<T> intersection = new ArrayList<T>(collection1);
intersection.retainAll(collection2);
return intersection;
booleanhasIntersection(Collection s1, Collection s2)
has Intersection
if (s1 == null || s2 == null)
    return false;
int n1 = s1.size();
int n2 = s2.size();
if (n2 < n1) {
    Collection<? extends T> t = s1;
    s1 = s2;
    s2 = t;
...
booleanhasIntersection(Collection a, Collection b)
Returns true if Collections have intersection.
return !isDisjoint(a, b);
booleanhasIntersection(Collection c1, Collection c2)
has Intersection
boolean flag = false;
for (T t : c2) {
    if (c1.contains(t)) {
        flag = true;
        break;
return flag;
...
booleanhasIntersection(Collection col1, Collection col2)
has Intersection
if (col2.size() < col1.size()) {
    Collection<T> tmp = col1;
    col1 = col2;
    col2 = tmp;
for (T item : col1) {
    if (col2.contains(item))
        return true;
...
booleanhasIntersection(final Collection a, final Collection b)
Returns true iff the given Collection s.
if (a.size() < 50 && b.size() < 50) {
    Iterator it = a.iterator();
    while (it.hasNext())
        if (b.contains(it.next()))
            return true;
} else if (a.size() < b.size()) {
    HashSet bSet = new HashSet(b);
    Iterator it = a.iterator();
...
Listintersect(Collection c1, Collection c2)
intersect
List c1_ = new ArrayList();
List c1__ = new ArrayList();
if (isNotEmpty(c1)) {
    c1_.addAll(c1);
    c1__.addAll(c1);
    c1__.removeAll(c2);
    c1_.removeAll(c1__);
return c1_;
Collectionintersect(Collection c1, Collection c2)
Computes the intersection between two collections
return intersect(c1, c2, null);
booleanintersect(Collection collection, Collection otherCollection)
intersect
return !Collections.disjoint(collection, otherCollection);