Java Collection Find isAnyIncludedIn(Collection findAnyOfThese, Collection inThisCollection)

Here you can find the source of isAnyIncludedIn(Collection findAnyOfThese, Collection inThisCollection)

Description

Checks if any of the elements in the first collection can be found in the second collection.

License

Apache License

Parameter

Parameter Description
findAnyOfThese which elements to look for.
inThisCollection where to look for them.
E type of the elements in question.

Return

true if any of the elements in findAnyOfThese can be found in inThisCollection , false otherwise.

Declaration

public static <E> boolean isAnyIncludedIn(Collection<E> findAnyOfThese,
        Collection<E> inThisCollection) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.Collection;

public class Main {
    /**/*w w w .j ava 2s  .c o m*/
     * Checks if any of the elements in the first collection can be found in the
     * second collection.
     *
     * @param findAnyOfThese which elements to look for.
     * @param inThisCollection where to look for them.
     * @param <E> type of the elements in question.
     * @return {@code true} if any of the elements in {@code findAnyOfThese} can
     *         be found in {@code inThisCollection}, {@code false} otherwise.
     */
    public static <E> boolean isAnyIncludedIn(Collection<E> findAnyOfThese,
            Collection<E> inThisCollection) {
        for (E findThisItem : findAnyOfThese) {
            if (inThisCollection.contains(findThisItem)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. findMax(Collection vals)
  2. findMax(Collection vals)
  3. findMax(Iterable collection)
  4. findValueOfType(Collection collection, Class type)
  5. findValueOfType(Collection collection, Class type)