Java tutorial
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static Object findFirstMatch(Collection source, Collection candidates) { if (!isEmpty(source) && !isEmpty(candidates)) { Iterator it = candidates.iterator(); Object candidate; do { if (!it.hasNext()) { return null; } candidate = it.next(); } while (!source.contains(candidate)); return candidate; } else { return null; } } public static boolean isEmpty(Collection collection) { return collection == null || collection.isEmpty(); } public static boolean isEmpty(Map map) { return map == null || map.isEmpty(); } }