Java Collection Contain isContained(Collection container, String strSearch)

Here you can find the source of isContained(Collection container, String strSearch)

Description

Test if any element in the container contains given string.

License

Open Source License

Parameter

Parameter Description
container - container of which elements will be searched to see if they contains given text
strSearch - text to search in the elements of specified container

Return

boolean - true if any of the elements in container contains given text

Declaration

public static boolean isContained(Collection<String> container, String strSearch) 

Method Source Code

//package com.java2s;
/*//from   w  w w . j  ava  2s.  c  o m
 * Copyright (C) 2003 - 2014 OpenSubsystems.com/net/org and its owners. All rights reserved.
 * 
 * This file is part of OpenSubsystems.
 *
 * OpenSubsystems is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */

import java.util.Collection;
import java.util.Iterator;

public class Main {
    /**
     * Test if any element in the container contains given string.
     * 
     * @param container - container of which elements will be searched to see if
     *                    they contains given text 
     * @param strSearch - text to search in the elements of specified container
     * @return boolean - true if any of the elements in container contains given 
     *                   text
     */
    public static boolean isContained(Collection<String> container, String strSearch) {
        boolean bReturn = false;

        if ((container != null) && (!container.isEmpty())) {
            for (Iterator<String> itrElements = container.iterator(); (itrElements.hasNext() && (!bReturn));) {
                if ((itrElements.next()).contains(strSearch)) {
                    bReturn = true;
                }
            }
        }

        return bReturn;
    }

    /**
     * Test if given string contains any element in the container.
     * 
     * @param container - container of which elements will be searched to see if
     *                    they are contained within given text 
     * @param strSearch - text to search in for the elements of specified container
     * @return boolean - true if the search text contains any of the elements in 
     *                   container
     */
    public static boolean contains(Collection<String> container, String strSearch) {
        boolean bReturn = false;

        if ((container != null) && (!container.isEmpty())) {
            for (Iterator<String> itrElements = container.iterator(); (itrElements.hasNext() && (!bReturn));) {
                if (strSearch.contains(itrElements.next())) {
                    bReturn = true;
                }
            }
        }

        return bReturn;
    }
}

Related

  1. containsString(String stringToCheck, Collection collection)
  2. containsStringIgnoreCase(Collection strings, String toCheck)
  3. getContainmentRelation(Collection a, Collection b)
  4. intersect(Collection container, Collection contained)
  5. isAnyElementContains(String str, Collection col)
  6. isNullOrContains(final Collection collection, final T item)
  7. stringContainsOneOfStringsFromCollection(final String pattern, final Collection collection)