Java Collection Intersect hasIntersection(Collection s1, Collection s2)

Here you can find the source of hasIntersection(Collection s1, Collection s2)

Description

has Intersection

License

Open Source License

Declaration

public static <T extends Object> boolean hasIntersection(Collection<? extends T> s1,
            Collection<? extends T> s2) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    public static <T extends Object> boolean hasIntersection(Collection<? extends T> s1,
            Collection<? extends T> s2) {
        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;//from ww w  .j  av  a  2s.  com
            s2 = t;
        }
        for (T e : s1) {
            if (s2.contains(e))
                return true;
        }
        return false;
    }

    public static int size(Collection<?> c) {
        return (c == null) ? 0 : c.size();
    }
}

Related

  1. getIntersection( final Collection> collections)
  2. getIntersection(Collection collection1, Collection collection2)
  3. hasIntersection(Collection a, Collection b)
  4. hasIntersection(Collection c1, Collection c2)
  5. hasIntersection(Collection col1, Collection col2)
  6. hasIntersection(final Collection a, final Collection b)