Java Collection Contain containsAny(Collection collection1, Collection collection2)

Here you can find the source of containsAny(Collection collection1, Collection collection2)

Description

Queries whether two collections intersect.

License

Open Source License

Parameter

Parameter Description
collection1 a collection
collection2 another

Return

true if they have any elements in common; false, otherwise

Declaration

public static boolean containsAny(Collection collection1, Collection collection2) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2002, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  ww  w  .  ja  v  a 2s.  c om
 *    IBM Corporation - initial API and implementation 
 ****************************************************************************/

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**
     * Queries whether two collections intersect.
     * 
     * @param collection1 a collection
     * @param collection2 another
     * 
     * @return <code>true</code> if they have any elements in common;
     *    <code>false</code>, otherwise
     */
    public static boolean containsAny(Collection collection1, Collection collection2) {
        Iterator it = collection2.iterator();
        while (it.hasNext()) {
            if (collection1.contains(it.next())) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. containsAll(final Collection c, final Object... array)
  2. containsAll(final Collection coll1, final Collection coll2)
  3. containSameElements(Collection> sets)
  4. containSameItems(Collection c1, Collection c2)
  5. containsAny(Collection c1, Collection c2)
  6. containsAny(Collection container, Collection contained)
  7. containsAny(Collection col1, Collection col2)
  8. containsAny(Collection source, Collection candidates)
  9. containsAny(Collection source, Object... candidates)