Here you can find the source of containsAny(Collection> source, Collection> candidates)
Parameter | Description |
---|---|
source | the source Collection |
candidates | the candidates to search for |
public static boolean containsAny(Collection<?> source, Collection<?> candidates)
//package com.java2s; import java.util.Collection; import java.util.Map; public class Main { /**/*from w w w .ja va 2 s. c o m*/ * Return {@code true} if any element in '{@code candidates}' is * contained in '{@code source}'; otherwise returns {@code false}. * @param source the source Collection * @param candidates the candidates to search for * @return whether any of the candidates has been found */ public static boolean containsAny(Collection<?> source, Collection<?> candidates) { if (isEmpty(source) || isEmpty(candidates)) { return false; } for (Object candidate : candidates) { if (source.contains(candidate)) { return true; } } return false; } /** * Return {@code true} if the supplied Collection is {@code null} * or empty. Otherwise, return {@code false}. * @param collection the Collection to check * @return whether the given Collection is empty */ public static boolean isEmpty(Collection<?> collection) { return (collection == null || collection.isEmpty()); } public static boolean isEmpty(Object[] objectArray) { return (objectArray == null || objectArray.length == 0); } /** * Return {@code true} if the supplied Map is {@code null} * or empty. Otherwise, return {@code false}. * @param map the Map to check * @return whether the given Map is empty */ public static boolean isEmpty(Map<?, ?> map) { return (map == null || map.isEmpty()); } }