Check if a collection contains Any elements from another Collection - Android java.util

Android examples for java.util:Collection Contains

Description

Check if a collection contains Any elements from another Collection

Demo Code


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

public class Main {
    public static void main(String[] argv) {
        Collection container = java.util.Arrays
                .asList("asdf", "book2s.com");
        Collection dataToCheck = java.util.Arrays.asList("asdf",
                "book2s.com");
        System.out.println(containAny(container, dataToCheck));
    }/*  ww  w.j a va2 s  .c  o  m*/

    public static <T> boolean containAny(Collection<T> container,
            Collection<T> dataToCheck) {
        for (T e : dataToCheck) {
            if (container.contains(e)) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials