Here you can find the source of containsAny(Collection collection1, Collection collection2)
Parameter | Description |
---|---|
collection1 | a collection |
collection2 | another |
true
if they have any elements in common; false
, otherwise
public static boolean containsAny(Collection collection1, Collection collection2)
//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; } }