Java Collection Contain containsString(String stringToCheck, Collection collection)

Here you can find the source of containsString(String stringToCheck, Collection collection)

Description

Checks if a given collection of strings already contains a given string.

License

Open Source License

Parameter

Parameter Description
stringToCheck the given string.
collection the given collection of type String .

Return

true in case the collection contains the given string, false otherwise.

Declaration

public static boolean containsString(String stringToCheck, Collection<String> collection) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

public class Main {
    /**//from  w  w  w. ja  v a 2  s . c om
     * Checks if a given collection of strings already contains a given string.
     * 
     * @param stringToCheck
     *            the given string.
     * @param collection
     *            the given collection of type {@link String}.
     * @return {@code true} in case the collection contains the given string, {@code false}
     *         otherwise.
     */
    public static boolean containsString(String stringToCheck, Collection<String> collection) {
        for (String item : collection) {
            if (item.equals(stringToCheck)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. containsSameType(Object o, Collection collection)
  2. containsSome(Collection source, Collection target)
  3. containsSome(final Collection c1, final Collection c2)
  4. containsSome(HashSet s1, Collection other)
  5. containsString(Collection coll, String str)
  6. containsStringIgnoreCase(Collection strings, String toCheck)
  7. getContainmentRelation(Collection a, Collection b)
  8. intersect(Collection container, Collection contained)
  9. isAnyElementContains(String str, Collection col)