check if a list contains Any element from another list - Java java.util

Java examples for java.util:List Contain

Description

check if a list contains Any element from another list

Demo Code


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

public class Main {
    public static void main(String[] argv) {
        List l1 = java.util.Arrays.asList("asdf", "java2s.com");
        List l2 = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(containsAny(l1, l2));
    }/* ww w.j a va2s .c  o m*/

    public static <T> boolean containsAny(List<T> l1, List<T> l2) {
        for (T elem : l1) {
            if (l2.contains(l1)) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials