Java Utililty Methods Collection Contain

List of utility methods to do Collection Contain

Description

The list of methods to do Collection Contain are organized into topic(s).

Method

booleancontainsString(Collection coll, String str)
contains String
for (String s : coll) {
    if (s != null && s.contains(str))
        return true;
return false;
booleancontainsString(String stringToCheck, Collection collection)
Checks if a given collection of strings already contains a given string.
for (String item : collection) {
    if (item.equals(stringToCheck)) {
        return true;
return false;
booleancontainsStringIgnoreCase(Collection strings, String toCheck)
Check if the collection has toCheck str in it, ignoring case sensitivity
if (toCheck == null) {
    return false;
for (Iterator it = strings.iterator(); it.hasNext();) {
    if (toCheck.equalsIgnoreCase((String) it.next())) {
        return true;
return false;
intgetContainmentRelation(Collection a, Collection b)
Assesses all the possible containment relations between collections A and B with one call.
Returns an int with bits set, according to a "Venn Diagram" view of A vs B.
NOT_A_SUPERSET_B: a - b != {}
NOT_A_DISJOINT_B: a * b != {} // * is intersects
NOT_A_SUBSET_B: b - a != {}
Thus the bits can be used to get the following relations:
for A_SUPERSET_B, use (x & CollectionUtilities.NOT_A_SUPERSET_B) == 0
for A_SUBSET_B, use (x & CollectionUtilities.NOT_A_SUBSET_B) == 0
for A_EQUALS_B, use (x & CollectionUtilities.NOT_A_EQUALS_B) == 0
for A_DISJOINT_B, use (x & CollectionUtilities.NOT_A_DISJOINT_B) == 0
for A_OVERLAPS_B, use (x & CollectionUtilities.NOT_A_DISJOINT_B) != 0
if (a.size() == 0) {
    return (b.size() == 0) ? ALL_EMPTY : NOT_A_SUPERSET_B;
} else if (b.size() == 0) {
    return NOT_A_SUBSET_B;
int result = 0;
for (Iterator it = a.iterator(); result != 6 && it.hasNext();) {
    result |= (b.contains(it.next())) ? NOT_A_DISJOINT_B : NOT_A_SUBSET_B;
...
Collectionintersect(Collection container, Collection contained)
intersect
Collection copy = new ArrayList(container);
copy.retainAll(contained);
return copy;
booleanisAnyElementContains(String str, Collection col)
is Any Element Contains
for (String url : col) {
    if (str.contains(url)) {
        return true;
return false;
booleanisContained(Collection container, String strSearch)
Test if any element in the container contains given string.
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;
booleanisNullOrContains(final Collection collection, final T item)
is Null Or Contains
return ((collection == null) || collection.contains(item));
booleanstringContainsOneOfStringsFromCollection(final String pattern, final Collection collection)
string Contains One Of Strings From Collection
boolean result = false;
for (final String string : collection) {
    if (pattern.contains(string)) {
        result = true;
        break;
return result;
...