non Empty Collection Intersection - Java java.util

Java examples for java.util:Collection Intersect

Description

non Empty Collection Intersection

Demo Code


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

public class Main {
    public static void main(String[] argv) {
        Collection collection1 = java.util.Arrays.asList("asdf",
                "java2s.com");
        Collection collection2 = java.util.Arrays.asList("asdf",
                "java2s.com");
        System.out.println(nonEmptyIntersection(collection1, collection2));
    }//from  www  . j  ava2s  .co  m

    public static boolean nonEmptyIntersection(
            Collection<? extends Object> collection1,
            Collection<? extends Object> collection2) {

        for (Object obj : collection1) {
            if (collection2.contains(obj)) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials