Java tutorial
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /** * Return the first element in '<code>candidates</code>' that is contained in * '<code>source</code>'. If no element in '<code>candidates</code>' is present in * '<code>source</code>' returns <code>null</code>. Iteration order is * {@link java.util.Collection} implementation specific. * * @param source the source Collection * @param candidates the candidates to search for * @return the first present object, or <code>null</code> if not found */ public static Object findFirstMatch(Collection source, Collection candidates) { if (isEmpty(source) || isEmpty(candidates)) { return null; } for (Object candidate : candidates) { if (source.contains(candidate)) { return candidate; } } return null; } /** * Return <code>true</code> if the supplied Collection is <code>null</code> * or empty. Otherwise, return <code>false</code>. * * @param collection the Collection to check * @return whether the given Collection is empty */ public static boolean isEmpty(Collection collection) { return (collection == null || collection.isEmpty()); } /** * Return <code>true</code> if the supplied Map is <code>null</code> * or empty. Otherwise, return <code>false</code>. * * @param map the Map to check * @return whether the given Map is empty */ public static boolean isEmpty(Map map) { return (map == null || map.isEmpty()); } }