Here you can find the source of containsAny(final Collection coll1, final Collection coll2)
true
iff at least one element is in both collections.
Parameter | Description |
---|---|
coll1 | the first collection, must not be null |
coll2 | the first collection, must not be null |
true
iff the intersection of the collections is non-empty
public static boolean containsAny(final Collection coll1, final Collection coll2)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { /**//from w ww . j a v a 2 s . c o m * Returns <code>true</code> iff at least one element is in both collections. * <p> * In other words, this method returns <code>true</code> iff the * {@link #intersection} of <i>coll1</i> and <i>coll2</i> is not empty. * * @param coll1 the first collection, must not be null * @param coll2 the first collection, must not be null * @return <code>true</code> iff the intersection of the collections is non-empty */ public static boolean containsAny(final Collection coll1, final Collection coll2) { if (coll1.size() < coll2.size()) { for (Iterator it = coll1.iterator(); it.hasNext();) { if (coll2.contains(it.next())) { return true; } } } else { for (Iterator it = coll2.iterator(); it.hasNext();) { if (coll1.contains(it.next())) { return true; } } } return false; } }