Checks whether the given source collection contains any of the items in the find Collection . - Java java.util

Java examples for java.util:Collection Contain

Description

Checks whether the given source collection contains any of the items in the find Collection .

Demo Code


//package com.java2s;
import java.util.Collection;

public class Main {
    public static void main(String[] argv) {
        Collection source = java.util.Arrays.asList("asdf", "java2s.com");
        Collection find = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(containsAny(source, find));
    }//from   w  w  w . ja v  a2  s . c om

    /**
     * Checks whether the given source collection contains any of the items in the find {@link Collection}.
     * 
     * @param source
     * @param find
     * @return
     */
    public static <T> boolean containsAny(Collection<T> source,
            Collection<T> find) {
        for (T tofind : find) {
            if (source.contains(tofind)) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials