Java Collection Intersect intersectsWith(Collection S1, Collection S2)

Here you can find the source of intersectsWith(Collection S1, Collection S2)

Description

check whether set S1 intersects with the set S2

License

Open Source License

Parameter

Parameter Description
S1 S1
S2 S2

Return

true if S1 and S2 intersect

Declaration

public static boolean intersectsWith(Collection<?> S1, Collection<?> S2) 

Method Source Code

//package com.java2s;
/* This file is part of the JFact DL reasoner
 Copyright 2011-2013 by Ignazio Palmisano, Dmitry Tsarkov, University of Manchester
 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
 You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA*/

import java.util.Collection;

public class Main {
    /**//from ww w  . j a v  a 2s  .  c o m
     * check whether set S1 intersects with the set S2
     * 
     * @param S1
     *        S1
     * @param S2
     *        S2
     * @return true if S1 and S2 intersect
     */
    public static boolean intersectsWith(Collection<?> S1, Collection<?> S2) {
        for (Object o : S1) {
            if (S2.contains(o)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. intersection(final Collection a, final Collection b)
  2. intersection(final Collection c1, final Collection c2)
  3. intersectionSize(Collection c1, Collection c2)
  4. intersects(Collection c1, Collection c2)
  5. intersects(Collection c0, Collection c1)
  6. makeIntersection(Collection a, Collection b)
  7. sizeOfIntersection(Collection a, Collection b)