Java List Contain containsAny(Set theList, Set toSearch)

Here you can find the source of containsAny(Set theList, Set toSearch)

Description

Checks to see if any elements of one set are present in another.

License

Open Source License

Parameter

Parameter Description
theList Set the elements to look for
toSearch Set the search set

Return

boolean true if any element in the first set is present in the second

Declaration

public static boolean containsAny(Set theList, Set toSearch) 

Method Source Code

//package com.java2s;
// The MIT License

import java.util.Set;

import java.util.Iterator;

public class Main {
    /**/*from   ww w .j  a va 2 s  .c  om*/
     * Checks to see if any elements of one set are present in another.
     * First parameter is the list of elements to search for, the second
     * parameter is the list to search in.  Basically tests to see if the two sets intersect
     * @param theList Set the elements to look for
     * @param toSearch Set the search set
     * @return boolean true if any element in the first set is present in the second
     */
    public static boolean containsAny(Set theList, Set toSearch) {

        if (toSearch.isEmpty())
            return false;
        else {
            Iterator iter = theList.iterator();
            while (iter.hasNext()) {
                Object obj = iter.next();
                if (toSearch.contains(obj))
                    return true;
            }
            return false;
        }
    }
}

Related

  1. containsAFloatingPointNumber(List values)
  2. containsAll(List list, T... items)
  3. containsAllIgnoreCase(List left, List right)
  4. containsAny(final String projectName, final List indicators)
  5. containsAny(List value, Object[] values)
  6. containsAnyOf(Exception e, List nonRetryableKeywords)
  7. containsArgument(List argList, Option option)
  8. containsAtLeastAValue(List values)
  9. containsAtLeastOneElement(List l1, List l2)