Java Collection Contain contains(Collection container, String strSearch)

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

Description

Test if given string contains any element in the container.

License

Open Source License

Parameter

Parameter Description
container - container of which elements will be searched to see if they are contained within given text
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

Declaration

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

Method Source Code

//package com.java2s;
/*//from   www.j a v a  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 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. contains(Collection objects, Object o)
  2. contains(Collection searchIn, Object[] find)
  3. contains(Collection stringCollection, String value)
  4. contains(Collection collection, A value)
  5. contains(Collection objectArray, Object element)
  6. contains(Collection mainCollection, String str)
  7. contains(Collection c1, Collection c2)
  8. contains(Collection collection, T item)
  9. contains(final Collection mimeTypes, final MimeType mimeType)

  10. HOME | Copyright © www.java2s.com 2016