Here you can find the source of contains(Collection
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 |
public static boolean contains(Collection<String> container, String strSearch)
//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; } }